mongosh के Basics
mongosh MongoDB commands और JavaScript चलाने के लिए interactive shell है।
In this page:
Syntax
mongosh
show dbs
use database_name
show collections
db.collection_name.find()
mongosh Basics
इसे mongosh से शुरू करें और यह default से localhost से connect होता है। Helpers में show dbs, use name, show collections, और db.stats() शामिल हैं।
यह एक JavaScript shell है, इसलिए आप variables, loops, और functions इस्तेमाल कर सकते हैं, और autocomplete के लिए Tab दबाएँ।
छोड़ने के लिए exit type करें।
Note:
- use dbname एक database पर switch करता है भले ही यह अभी exist न करता हो।
- यह पहले write पर बनता है।
उदाहरण: mongosh basics
test> show dbs
admin 40.00 KiB
config 60.00 KiB
local 72.00 KiB
test> use shop
switched to db shop
shop> db.products.insertOne({ name: "Pen", price: 3 })
{ acknowledged: true, insertedId: ObjectId('65a1b2c3d4e5f60718293a4c') }
shop> show collections
products
shop> exit
⚠️ 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. #}
आम गलतियां
- काम करने से पहले use चलाना भूल जाना
- db (current database) को एक collection से confuse करना
- यह उम्मीद करना कि semicolons required हैं
चैप्टर सारांश
- mongosh एक JavaScript shell है
- show dbs, use, show collections जैसे commands मिलते हैं
- db current database को refer करता है
- Databases पहले write पर बनते हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: