0% found this document useful (0 votes)
21 views4 pages

Operators in Mongodb

The document provides an overview of MongoDB operators, which are special symbols or keywords used to perform mathematical or logical operations within the database. It categorizes these operators into types such as comparison, logical, element, evaluation, array, and comment operators, each serving specific functions for querying and interacting with data. The document includes descriptions and examples of various operators to enhance the understanding of their usage in MongoDB.

Uploaded by

Sonia Bajaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Operators in Mongodb

The document provides an overview of MongoDB operators, which are special symbols or keywords used to perform mathematical or logical operations within the database. It categorizes these operators into types such as comparison, logical, element, evaluation, array, and comment operators, each serving specific functions for querying and interacting with data. The document includes descriptions and examples of various operators to enhance the understanding of their usage in MongoDB.

Uploaded by

Sonia Bajaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 4: To understand the operators in MongoDB.

THEORY:What are MongoDB operators?

MongoDB offers different types of operators that can be used to interact with the database.
Operators are special symbols or keywords that inform a compiler or an interpreter to carry out
mathematical or logical operations.

The query operators enhance the functionality of MongoDB by allowing developers to create
complex queries to interact with data sets that match their applications.

MongoDB offers the following query operator types:

Comparison

Logical

Element

Evaluation

Array

Comments

MongoDB operators can be used with any supported MongoDB command.

Comparison Operators

MongoDB comparison operators can be used to compare values in a document. The following
table contains the common comparison operators.

Operator Description

$eq Matches values that are equal to the given value.

$gt Matches if values are greater than the given value.


$lt Matches if values are less than the given value.

$gte Matches if values are greater or equal to the given value.

$lte Matches if values are less or equal to the given value.

$in Matches any of the values in an array.

$ne Matches values that are not equal to the given value.

$nin Matches none of the values specified in an array.

Logical Operators

MongoDB logical operators can be used to filter data based on given conditions. These
operators provide a way to combine multiple conditions. Each operator equates the given
condition to a true or false value.

Here are the MongoDB logical operators:

Operator Description

$and Joins two or more queries with a logical AND and returns the documents that match all
the conditions.

$or Join two or more queries with a logical OR and return the documents that match either
query.

$nor The opposite of the OR operator. The logical NOR operator will join two or more queries
and return documents that do not match the given query conditions.

$not Returns the documents that do not match the given query expression.

Element Operators

The element query operators are used to identify documents using the fields of the document.
The table given below lists the current element operators.
Operator Description

$existsMatches documents that have the specified field.

$type Matches documents according to the specified field type. These field types are specified
BSON types and can be defined either by type number or alias.

Evaluation Operators

The MongoDB evaluation operators can evaluate the overall data structure or individual field in a
document. We are only looking at the basic functionality of these operators as each of these
operators can be considered an advanced MongoDB functionality. Here is a list of common
evaluation operators in MongoDB.

Operator Description

$jsonSchema Validate the document according to the given JSON schema.

$mod Matches documents where a given field’s value is equal to the remainder after being
divided by a specified value.

$regex Select documents that match the given regular expression.

$text Perform a text search on the indicated field. The search can only be performed if the
field is indexed with a text index.

$whereMatches documents that satisfy a JavaScript expression.Matches documents that


match specified $elemMatch conditions within each array element.

Array Operators

MongoDB array operators are designed to query documents with arrays. Here are the array
operators provided by MongoDB.

Operator Description

$all Matches arrays that contain all the specified values in the query condition.

$size Matches the documents if the array size is equal to the specified size in a query.

$elemMatch Matches documents that match specified $elemMatch conditions within each
array element.

Comment Operator

The MongoDB comment query operator associates a comment to any expression taking a query
predicate. Adding comments to queries enables database administrators to trace and interpret
MongoDB logs using the comments easily.

You might also like