Logical Operators In MongoDB

Logical Operators In MongoDB

MongoDB supports logical query operators. These operators are used for filtering the data and getting precise results based on the given conditions. The following table contains the comparison query operators:

Matching values using $and operator:

In this example, we are retrieving only those employee’s documents whose status is ACTIVE and vacations is 1.

//Example

db.q_employee.find({ $and: [{"status": "ACTIVE"}, {"vacations": {$gte: 1, $lte: 3}}]})

Matching values using $nor operator:

In this example, we are retrieving only those employee’s documents whose status is not INACTIVE and whose role is not MANAGER.

//Example

db.q_employee.find({ $nor: [{"status": "INACTIVE"}, {"ROLE": "MANAGER"}]})

Matching values using $or operator:

In this example, we are retrieving only those employee’s documents whose status is ACTIVE or vacations is 1.

//Example

db.q_employee.find({ $or: [{"status": "ACTIVE"}, {"vacations": 1}]})

Matching values using $not operator:

In this example, we are retrieving only those employee’s documents whose vacations is not greater than 3.

//Example

db.q_employee.find({vacations: {$not: {$gt: 3}}})

Read more

Retrieval-Augmented Generation (RAG): A Complete Guide to Architecture, Workflow, Use Cases, and Implementation

Retrieval-Augmented Generation (RAG): A Complete Guide to Architecture, Workflow, Use Cases, and Implementation

Category: Artificial Intelligence | Generative AI | Software Engineering 1. Introduction Large Language Models (LLMs) have transformed how applications interact with users by enabling natural language understanding, content generation, summarization, and conversational experiences. However, traditional LLMs have limitations. They may not know an organization's private information, may lack access to

By Sangram Ekshinge