mongodb

3 Best Ways to CREATE MongoDB Collections [Backup/Restore]

How do you CREATE  MongoDB Collections”? ”How many types to CREATE a collection”?

In this section, I am going to describes Create Collections in MongoDB. Below version 3.4, does not provide any user interface like SQL Server or Robomongo but MongoDB 3.4 solve this problem with help of Robomongo Management Tool.

As per my understanding, it is a great achievement of MongoDB to provide us Robomongo Management Tool.

You can Download  Robomongo Management Tool and install MongoDB & Robomongo in your machine and start to create MongoDB database, create MongoDB collections, create MongoDB functions and create MongoDB users.



[Video URL] - CREATE MongoDB Collection using “Robomongo Tool”!

Keep in Mind for MongoDB collections; You do not need to create a collection because MongoDB creates automatically, when you insert a document in a collection.

3 Ways” to CREATE MongoDB collection:
1.            “Use” of Robomongo Management Tool.
2.            “Use” Command Line.
3.            “Use” ASP.Net C# Code.

Here you can decide to create MongoDB database, collections and users.

CREATE MongoDB Collections Using Robomongo Tool:-
You should go (download URL: https://robomongo.org/) and install user interface. It’s so easy to install and start MongoDB developments.

1.            Use” the database.
2.            Select” thee Database collections folder.
3.            CREATE” a new collection.
4.            In the Final, you “verify” to the created collection.

Example,
CREATE MongoDB Collections Using Command:-
Create a MongoDB Collection using command in the following steps,

1.            Use” the database.
2.             “CREATE” a new collection using “db.createCollection()” method.
3.            In the Final, you “verify” to the created collection.

Examples,

Basic Syntax:

-- Show Database dbs.
> show dbs
admin    0.000GB
local    0.000GB
myNewDB  0.000GB

-- Use Your Database to perform Collections.
> use myNewDB
switched to db myNewDB

-- Create Collection with Name
> db.createCollection("Customers")
{ "ok" : 1 }

-- Show all Created Collections.
> show collections
Customers
users

-- Important options [capped , size, validator,indexOptionDefaults, MIN and MAX] for a collection.
> db.createCollection("Orders", {capped:true, size :6142800.0, max:10000.0 })
{ "ok" : 1 }

-- Insert/Show Rows in a Collection.
> db.Venders.insert({"name" : "Vender 1", "Term":"12 Months", "Country": "India"})
WriteResult({ "nInserted" : 1 })

> db.Venders.find()
{ "_id" : ObjectId("58577f0867fb39baecd1e0ce"), "name" : "Vender 1", "Term" : "12 Months", "Country" : "India" }
>

Reference links,


I hope you are enjoying with this post! Please share with you friends. Thank you!!

ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.