MongoDB Working Commands

Mongodb uses JavaScript interpreter like in browser. You can run commands like in Chrome DevTools on mongodb for insertion etc.

show dbs
> print(“test”)
test
> var arr=[‘1′,’2’]
> arr
[ “1”, “2” ]
> use learning_mongo
switched to db learning_mongo
> for(i=0;i<1000;i++){
… db.numbers.insert(
… {‘number’:i})}
WriteResult({ “nInserted” : 1 })
> db.numbers.count()
1000

 

db.numbers.find({‘number’:556})
{ “_id” : ObjectId(“5a5b7f5c5a887e7aadb86393”), “number” : 556 }

> db.numbers.find({‘number’:556}).explain()
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “learning_mongo.numbers”,
“indexFilterSet” : false,
“parsedQuery” : {
“number” : {
“$eq” : 556
}
},
“winningPlan” : {
“stage” : “COLLSCAN”,
“filter” : {
“number” : {
“$eq” : 556
}
},
“direction” : “forward”
},
“rejectedPlans” : [ ]
},
“serverInfo” : {
“host” : “BLRSVAKA168443”,
“port” : 27017,
“version” : “3.2.10”,
“gitVersion” : “79d9b3ab5ce20f51c272b4411202710a082d0317”
},
“ok” : 1
}

db.numbers.find({‘number’:556}).explain(‘executionStats’)
{
“queryPlanner” : {
“plannerVersion” : 1,
“namespace” : “learning_mongo.numbers”,
“indexFilterSet” : false,
“parsedQuery” : {
“number” : {
“$eq” : 556
}
},
“winningPlan” : {
“stage” : “COLLSCAN”,
“filter” : {
“number” : {
“$eq” : 556
}
},
“direction” : “forward”
},
“rejectedPlans” : [ ]
},
“executionStats” : {
“executionSuccess” : true,
“nReturned” : 1,
“executionTimeMillis” : 0,
“totalKeysExamined” : 0,
“totalDocsExamined” : 1000,
“executionStages” : {
“stage” : “COLLSCAN”,
“filter” : {
“number” : {
“$eq” : 556
}
},
“nReturned” : 1,
“executionTimeMillisEstimate” : 0,
“works” : 1002,
“advanced” : 1,
“needTime” : 1000,
“needYield” : 0,
“saveState” : 7,
“restoreState” : 7,
“isEOF” : 1,
“invalidates” : 0,
“direction” : “forward”,
“docsExamined” : 1000
}
},
“serverInfo” : {
“host” : “BLRSVAKA168443”,
“port” : 27017,
“version” : “3.2.10”,
“gitVersion” : “79d9b3ab5ce20f51c272b4411202710a082d0317”
},
“ok” : 1
}

> db.numbers.createIndex({number:1})
{
“createdCollectionAutomatically” : false,
“numIndexesBefore” : 1,
“numIndexesAfter” : 2,
“ok” : 1
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s