MongoDB Create Collection In Hindi | MongoDB List Collections

📔 : MongoDB 🔗

पिछले topic में आपने database create करना सीखा , इस topic में हम collection को create और list करना सीखेंगे।

MongoDB में Collection एक तरह से database में Table create करना है। collection create करने के लिए db.createCollectio() function का use किया जाता है।

Create Collection In MongoDB

Collection create समय आपको कोई structure define करने की जरूरत नहीं है जैसे आपको SQL databases में Table create करते time data types define करने की जरूरत पड़ती है।

क्योंकि collection में data key:pair में store होता है मतलब key का नाम हर record में different हो सकता है।

db.createCollection("users")

ऊपर दी गयी command को run करने पर आपको confirmation message दिखेगा - collection successfully created .

इसके अलावा आप , directly data को insert कराते समय भी collection को create कर सकते हैं।

db.users.insertOne(object)

इससे अगर collections exist होगा तो record insert हो जायगा नहीं तो new collection create होकर record insert हो जायगा।

List all collections in MongoDB

database में सभी collections को list करने के लिए show collections command का use use किया जाता है।

show collections

Again , अगर collection empty है मतलब उसमे उसमे कोई document / record या data नहीं है तो वो collection list में नहीं दिखेगा , आपको वही collections दिखेंगे जो empty नहीं है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers