---
title: "Write a MongoDB query to find all documents in a collection with a specific condition."  
description: "Write a MongoDB query to find all documents in a collection with a specific condition."  
author: "Steilla Mitchel"  
published: 2023-07-26  
updated: 2023-07-27  
canonical: https://www.mindstick.com/forum/159295/write-a-mongodb-query-to-find-all-documents-in-a-collection-with-a-specific-condition  
category: "mongodb"  
tags: ["database", "mongodb"]  
reading_time: 3 minutes  

---

# Write a MongoDB query to find all documents in a collection with a specific condition.

Write a [MongoDB query](https://www.mindstick.com/forum/159307/write-a-mongodb-query-to-update-specific-fields-in-multiple-documents-in-a-collection) to find all [documents](https://www.mindstick.com/articles/156931/the-main-types-of-business-documents) in a [collection](https://www.mindstick.com/articles/1718/collections-in-java) with a specific condition.

## Replies

### Reply by Aryan Kumar

Sure, here is an example of a [MongoDB](https://www.mindstick.com/articles/337565/understanding-document-stores-a-look-at-mongodb-vs-couchdb) [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) to find all documents in a collection with the specific condition:

```plaintext
db.collection.find({
  field: value,
});
```

For example, the following query would find all documents in the `users` collection where the `name` field is equal to "John Doe":

```plaintext
db.users.find({
  name: "John Doe",
});
```

The `find()` method takes a document as its parameter, which specifies the criteria for the query. The document can contain any number of fields, and each field can have any value. The `find()` method will return all documents that match the criteria.

In addition to the `find()` method, MongoDB also provides a number of other query methods, such as `findOne()`, `findAndModify()`, and `aggregate()`. These methods can be used to perform more complex queries.

Here is a table of some of the most common MongoDB query operators:

| Operator | Description |
| --- | --- |
| `$eq` | The `eq` operator matches documents where the value of a field is equal to a specified value. |
| `$ne` | The `ne` operator matches documents where the value of a field is not equal to a specified value. |
| `$gt` | The `gt` operator matches documents where the value of a field is greater than a specified value. |
| `$lt` | The `lt` operator matches documents where the value of a field is less than a specified value. |
| `$gte` | The `gte` operator matches documents where the value of a field is greater than or equal to a specified value. |
| `$lte` | The `lte` operator matches documents where the value of a field is less than or equal to a specified value. |
| `$in` | The `in` operator matches documents where the value of a field is one of a specified set of values. |
| `$nin` | The `nin` operator matches documents where the value of a field is not one of a specified set of values. |
| `$and` | The `and` operator matches documents where the value of two or more fields meet the specified conditions. |
| `$or` | The `or` operator matches documents where the value of two or more fields meet at least one of the specified conditions. |


---

Original Source: https://www.mindstick.com/forum/159295/write-a-mongodb-query-to-find-all-documents-in-a-collection-with-a-specific-condition

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
