Query Document Examples
-
Valid queries on a text field:
{employee:”Bob”}
{ employee : “Bob” }
{ ‘employee’ : “Bob” }
{ “employee” : “Bob” }
-
Invalid query on a text field:
{ employee : Bob }
-
Valid queries on a numeric field:
{salary:50000}
{ salary : {$gt:30000} }
-
Invalid query on a numeric field:
{ salary : “50000” }
-
Valid query on an array field:
{ rating: {$elemMatch: {$lt: 5}} }
This is the syntax for, Single element satisfies the criteria. This query looks for a document where the rating array contains at least one value that is less than 5
-
Invalid query on an array field:
{ rating: 5 }
-
Special invalid case:
{_id: "53ac6148a4a4be23e92bb6f1"}
This is an invalid query, because _id is an ObjectId object created by MongoDB that cannot be matched to a string.