0% found this document useful (0 votes)
10 views

Mongodb

Uploaded by

Arayn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Mongodb

Uploaded by

Arayn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Mongo Db Tutorial

=========================
=========================

test> show dbs;


===============
-> this command shows all the availbale databases in your pc

output:-
=======
admin 40.00 KiB
config 72.00 KiB
local 88.00 KiB
students 72.00 KiB

test> use dbtutorial;


==================
-> this command create the database dbtutorial if not present and switches to the
dbtutorial datbase and if present already then it switches to that database.

output:-
========
switched to db dbtutorial

dbtutorial> db.createCollection("students");
=======================================
-> this command will create a new collection named "students" inside the database
dbtutorial.

output:-
========
{ ok: 1 }

dbtutorial> db.students.insertOne({name:"Aryan
Gupta",gmail:"[email protected]"});
============================================
-> this command will insert a document inside a collection

syntax:-
========
db.<collection_name>.insertOne({property:value,...});

output:-
=========
{
acknowledged: true,
insertedId: ObjectId("655c86ec381a9e8106fc1ef0")
}

dbtutorial> db.students.find();
===========================
-> this command will display all documents present inside a collection.

output:-
========
[
{
_id: ObjectId("655c86ec381a9e8106fc1ef0"),
name: 'Aryan Gupta',
gmail: '[email protected]'
},
{
_id: ObjectId("655c895b381a9e8106fc1ef1"),
name: 'Anshi Gupta',
gmail: '[email protected]'
}
]

dbtutorial> db.students.find({name:"Aryan Gupta"});


==============================================
-> this method will find the document inside the collection students which has name
equal to "Aryan Gupta".

output:-
========
[
{
_id: ObjectId("655c86ec381a9e8106fc1ef0"),
name: 'Aryan Gupta',
gmail: '[email protected]'
}
]

dbtutorial> db.students.find({name:"Anshi Gupta"}).limit(2);


===================================================
-> This command will find all the document inside the collection students whose
name value is "Anshi Gupta" and also only shows 2 document, i.e, it will limit the
no of documents displayed.

output:-
=========
[
{
_id: ObjectId("655c895b381a9e8106fc1ef1"),
name: 'Anshi Gupta',
gmail: '[email protected]'
},
{
_id: ObjectId("655c8b00381a9e8106fc1ef2"),
name: 'Anshi Gupta',
gmail: '[email protected]'
}
]

You might also like