move C:mongodb-win32-5-* C:mongodb
Step 3: Create a folder named data and inside the data folder creates another folder called DB eg: c://datadb.
Step 4: MongoDB can be installed using the following command in cmd and if it shows the message “waiting for connections” after executing the code, it means that process has started successfully.
C:mongodbbinmongod.exe
Step 5:Open a new cmd window and type in the following command to open the mogoDb shell. Once the command is successfully executed, the command shell for mongoDB will be opened.
C:mongodbbinmongo.exe
MongoDB Basic Operations:
1.Database creation: You need not define a structure for mongoDB , everything will be processed created on the fly. you can create a database using the command “use db_name” .The database will not be displayed until some document is inserted into the database. In mongoDB tables are called “collections.” Use the following commands to create a database and collection in mongoDB.
db -->Lists the current database in use use database_name -->database will be created with the given name. show dbs -->lists all the databases
2.Document Creation: It is possible to create documents before inserting it into a collection. Here i have created two documents.
Company_info = ({name : "cloudtechies" , type : "blog" } )
Technology_base = ({ base : "cloud technology" , Type: "tutorials" } )
3.Inserting Documents into collections: Use the following commands to insert the documents into a collection.
db.orginfo.insert(company_info)
db.orginfo.insert(technology_base)
show collections
4. Using For Loop For Inserting Documents: You can insert documents through various iterations using a for loop. Use the following syntax for inserting documents using for loop.
for ( var i = 0 ; var i <=10 ; i ++)
db.demofor.insert({ x : i-- , j : i } )
5.Retrieving Documents From Collections: find() function is used to list all the documents in a collection. By default, it only displays first 20 results.For next 20 results you just have to type “it”.
Syntax: db.collection_name.find()
db.orginfo.find()
it
6. Using Cursors For Selecting a specific file: By assigning the find results to a variable you can find the specific document through the array index. “Printjson” function prints the selected files.
var list= db.demofor.find()
printjson (list[4])