For inserting the data into mongoDB open the command prompt in windows and connect the server by typing mongod and click enter later . Open the other command prompt and type mongo to open the shell to write the program
INSERT:
Syntax : db.collection.insert()
db.collection.insert() adds
the new records in to the specified collection in the form of Key Value pair.
Example 1 : ( Basic Insertion in Mongodb )
db.students.insert (
{
‘Name’:’Venkatesh’,
’Age’:’23’
}
)
In the above Query Students is the Collection of which we are going to insert data into it. You can find the “nInserted” : no of records you have inserted. This
represents the successful insertion of Data.
Example 1: ( Schema less insertion in Mongodb )
db.students.insert (
{
'Name':'Ramesh',
'Age':'25',
'Address':
[ {'State':'Andhra Pradesh', 'City' : 'Nellore', 'pinncode':'524401'}]
}
)
In the above Query you have
added additional values for 'Address', in structured Query language we
have to create the additional column for the table and then insert into it. But
in Mongo we can directly insert the data into collection by passing additional
columns. this represents the Schema less insertion in Mongodb.