MongoDb $ and the operator with geospatial queries

I am working on a Java system, part of which maps expressions from an internal representation to a MongoDb request. I develop the expressions "AND" in the same way as for the expressions "OR". Therefore, if I have an expression like "category =" GIBBLY "AND active = true", it will display as:

{$and:[{"category":"GIBBLY"},{"active":true}]}

I understand that in this case it is not necessary. I can’t understand if there is ever a case when $ is necessary (on my system there will often be nested AND and OR, if that matters).

The reason this is a problem for me is because $ and the operator seem to be failing for geospatial queries. The request is:

{"$and":[{"loc":{"$nearSphere":[-79.75 , 43.5], "$maxDistance":0.00156787}}, {"active":true}]}

fails with the error "cannot find special index: 2d". If I re-request as:

{"loc":{"$nearSphere":[-79.75 , 43.5], "$maxDistance":0.00156787}, "active":true}

It works great.

I tried to do some research and found a discussion of the problem in the mongodb user group , which talked about discussing composite indexes in geospatial queries .

None of the information found explains why exactly $ does not work with geospatial query. I have no composite indexes that are not defined at all in my database, and not $ and query work, so I'm not sure how $ works differently with respect to indexes.

To summarize, my questions are:

  • Is $ ever necessary, and if so, in what cases?

  • Does $ and in some fundamental way differ from the implicit representation with respect to indices?

  • $ ?

+5
2

$ - , , ?

SQL

SELECT * FROM Table
WHERE (x = 1 OR y = 0)
AND   (w = 1 OR z = 0)

$and . :

db.Table.find({$or: [{x:1},{y:0}] , $or: [{w:1},{z:0}]})

"" , JSON. , $or. "", .

$and .

$ - ?

. , .

$ ?

, , , : http://jira.mongodb.org/

, , , MongoDB . .

+4

, , "":

db.collection.find({name: "Jenna", number: 1})

$ , , . , , 2 10, $ operator:

:

{_id: 1, array: [1, 10]}
{_id: 2, array: [2, 10]}

:

> db.collection.find({$and: [{array: 2}, {array: 10}]})
{_id: 2, array: [2, 10]}

$ "array: 10" :

> db.collection.find({array: 2, array: 10})
{_id: 1, array: [1, 10]}
{_id: 2, array: [2, 10]}

$ . .

, JIRA, $ , .

+3

All Articles