MongoDB Query and Projection OperatorThe MongoDB query operator includes comparison, logical, element, evaluation, Geospatial, array, bitwise, and comment operators. MongoDB Comparison Operators$eqThe $eq specifies the equality condition. It matches documents where the value of a field equals the specified value. Syntax: Example: The above example queries the books collection to select all documents where the value of the price filed equals 300. $gtThe $gt chooses a document where the value of the field is greater than the specified value. Syntax: Example: $gteThe $gte choose the documents where the field value is greater than or equal to a specified value. Syntax: Example: $inThe $in operator choose the documents where the value of a field equals any value in the specified array. Syntax: Example: $ltThe $lt operator chooses the documents where the value of the field is less than the specified value. Syntax: Example: $lteThe $lte operator chooses the documents where the field value is less than or equal to a specified value. Syntax: Example: $neThe $ne operator chooses the documents where the field value is not equal to the specified value. Syntax: Example: $ninThe $nin operator chooses the documents where the field value is not in the specified array or does not exist. Syntax: Example: MongoDB Logical Operator$andThe $and operator works as a logical AND operation on an array. The array should be of one or more expressions and chooses the documents that satisfy all the expressions in the array. Syntax: Example: $notThe $not operator works as a logical NOT on the specified expression and chooses the documents that are not related to the expression. Syntax: Example: $norThe $nor operator works as logical NOR on an array of one or more query expression and chooses the documents that fail all the query expression in the array. Syntax: Example: $orIt works as a logical OR operation on an array of two or more expressions and chooses documents that meet the expectation at least one of the expressions. Syntax: Example: MongoDB Element Operator$existsThe exists operator matches the documents that contain the field when Boolean is true. It also matches the document where the field value is null. Syntax: Example: $typeThe type operator chooses documents where the value of the field is an instance of the specified BSON type. Syntax: Example: MongoDB Evaluation Operator$exprThe expr operator allows the use of aggregation expressions within the query language. Syntax: Example: $jsonSchemaIt matches the documents that satisfy the specified JSON Schema. Syntax: $modThe mod operator selects the document where the value of a field is divided by a divisor has the specified remainder. Syntax: Example: $regexIt provides regular expression abilities for pattern matching strings in queries. The MongoDB uses regular expressions that are compatible with Perl. Syntax: Example: $textThe $text operator searches a text on the content of the field, indexed with a text index. Syntax: Example: $whereThe "where" operator is used for passing either a string containing a JavaScript expression or a full JavaScript function to the query system. Example: MongoDB Geospatial Operator$geoIntersectsIt selects only those documents whose geospatial data intersects with the given GeoJSON object. Syntax: Example: $geoWithinThe geoWithin operator chooses the document with geospatial data that exists entirely within a specified shape. Syntax: $nearThe near operator defines a point for which a geospatial query returns the documents from close to far. Syntax: Example: $nearSphereThe nearsphere operator specifies a point for which the geospatial query returns the document from nearest to farthest. Syntax: Example: $allIt chooses the document where the value of a field is an array that contains all the specified elements. Syntax: Example: $elemMatchThe operator relates documents that contain an array field with at least one element that matches with all the given query criteria. Syntax: Example: $sizeIt selects any array with the number of the element specified by the argument. Syntax: MongoDB Bitwise Operator$bitsAllClearIt matches the documents where all the bit positions given by the query are clear infield. Syntax: Example: $bitsAllSetThe bitallset operator matches the documents where all the bit positions given by the query are set in the field. Syntax: Example: $bitsAnyClearThe bitAnyClear operator matches the document where any bit of positions given by the query is clear in the field. Syntax: Example: $bitsAnySetIt matches the document where any of the bit positions given by the query are set in the field. Syntax: Example: MongoDB comments operator$commentThe $comment operator associates a comment to any expression taking a query predicate. Syntax: Example: MongoDB Projection Operator$The $ operator limits the contents of an array from the query results to contain only the first element matching the query document. Syntax: $elemMatchThe content of the array field made limited using this operator from the query result to contain only the first element matching the element $elemMatch condition. Syntax: $metaThe meta operator returns the result for each matching document where the metadata associated with the query. Syntax: Example: $sliceIt controls the number of values in an array that a query returns. Syntax: Example: Next TopicMongoDB Update Operator |