consider the following documnet structure:
{
"_id" : <ObjectId>,
"name" : <string>,
"contact" : {
"phone" : <string>
"email" : <string>
"location" : [ <longitude>, <latitude> ]
},
"stars" : int,
"categories" : <array of strings>
"grades" : <array of integers>,
}
according to mongodb website the following query specify
the stars field is greater than or equal to 2 and less than 5, AND the categories field equals "Bakery" (or if categories is an array, contains the string "Bakery" as an element):
collection.find(
new Document("stars", new Document("$gte", 2)
.append("$lt", 5))
.append("categories", "Bakery")).forEach(printBlock);
- can someone explain me the structure of the query?
- why a new document is created (new Document("$gte", 2)?
The query looks like this:
new Document("$gte", 2) has been invoked to create the inner json: {$gte : 2, $lt : 5}