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 ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers