1

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);
  1. can someone explain me the structure of the query?
  2. why a new document is created (new Document("$gte", 2)?

1 Answer 1

1

The query looks like this:

{"stars"      : {$gte : 2, $lt : 5}
 "categories" : "Bakery"}

new Document("$gte", 2) has been invoked to create the inner json: {$gte : 2, $lt : 5}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.