← Back to MongoDB Course | Chapter 3: CRUD — Read | Lesson 1 of 7

find() का उपयोग

find एक collection के सारे documents return करता है, या वे जो एक filter match करते हैं।

In this page:

  1. find()
Syntax
javascript
db.collection_name.find(filter, projection)
db.collection_name.find({ field: value })

find()

db.collection.find(filter, projection) matching documents पर एक cursor return करता है। एक empty या missing filter सब कुछ match करता है। mongosh में पहले 20 results automatically print होते हैं, और ज़्यादा देखने के लिए आप it type कर सकते हैं।

Note: बिना arguments के find सब कुछ return करता है, इसलिए बड़ी collections पर एक filter add करें।

उदाहरण: find()

bash
test> db.users.insertMany([
...   { _id: 1, name: "Ada", age: 36, city: "London" },
...   { _id: 2, name: "Bob", age: 25, city: "Oslo" },
...   { _id: 3, name: "Cy", age: 41, city: "Oslo" }
... ])
{ acknowledged: true, insertedIds: { '0': 1, '1': 2, '2': 3 } }
test> db.users.find()
[
  { _id: 1, name: 'Ada', age: 36, city: 'London' },
  { _id: 2, name: 'Bob', age: 25, city: 'Oslo' },
  { _id: 3, name: 'Cy', age: 41, city: 'Oslo' }
]
test> db.users.find({ city: "Oslo" })
[
  { _id: 2, name: 'Bob', age: 25, city: 'Oslo' },
  { _id: 3, name: 'Cy', age: 41, city: 'Oslo' }
]

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह भूल जाना कि find एक cursor return करता है, array नहीं
  2. बिना filter या limit के huge collections पर find चलाना
  3. collection name misspell करना और एक empty result पाना
चैप्टर सारांश
  • find(filter, projection) एक cursor return करता है
  • Empty filter सब कुछ match करता है
  • mongosh पहले 20 print करता है
  • बड़े data पर filters और limits add करें
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.