1. mongod:- start mongodb server
2. mongo:- connecting to DB
3. use pcat:- create new DB & switch to specific DB
4. db:- show current db in use
5. db.stats:- shows current DB useage information
6. show dbs:- shows dbs that avaliable.
7. show collections:- show the records created inside the DB.
8. db.sample.insert({a:1,b:"a string",someOthersfeild:22.34})
9. db.sample.find()
10. db.sample.find().pretty()
11. db.sample.find().toArray()
12. var x = db.sample.find().toArray()
13. db.getLastError()
14. db.sample.update({_id:99},{"_id":99,"p":14})
15. db.sample.findOne()
16. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$set:{E_ID:1110}}) :- this will do partial update of the document by only updating the E_ID value.
17. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$inc:{E_ID:1}}) :- This will increment the E_ID value by 1 i.e E_ID :1111
18. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$push:{Dig:"Sr.PL"}}) :- This will insert a new array to the document. and array will keep on increasing if needed.
19. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$addToSet:{Dig:"Sr.PL"}}) :- This will insert a record onle if didn't exist.
20. db.sample.find({_id:100}):- this will display the only document in the collections for given that matchs the _id.
21. db.sample.find({_id:100}).count() :- This will display the count of document exist with given _id.
22. db.sample.remove({_id:100}) :- This remove the document from the collection for given _id.
23. db.sample.remove({}) :- this will remove all documents in the given "sample" collection.
24. db.sample.remove({x:/ra/})
24. mongoimport -d pcat -c test2 test.json :- this import the data from the file. pcat is a DB, test.json is a dbfile, test2 is collection.
Multiple documents update
25. db.sample.update({Order_id:12345},{name:raj},[false,[false]]) :-
26. db.users.update({_id: "Jane"}, {$addToSet: {likes: "football"}}, {upsert: true})
---------------------------------------------------------------------------------------------------------------
Buld Write Operations:-
var bulk = db.items.initializeUnorederedBulkOp();
db.items.find()
bulk.insert({item:"abcd",Qty:230,stats:"A",point:100})
db.items.find()
bulk.execute()
var b = db.items.initializeOrederedBulkOp();
b.find({item:"abcd"}).remove()
b.find.({item:"ijk123"}).update({$inc:{points:1}})
b.execute()
----------------------------------------------------------------------------------------------------------------
Commands:-
DBA Commands::
drop()
create()
compact()
serverStatus()
replSetGetStatus()
addShard()
User Comands::
aggregate()
MapReduce()
count()
FindAndModify()
getLastError()
isMaster()
help
db.runCommand({isMaster:1})
db.runCommand({isMaster})
db.isMaster()
db.isMaster:- this will give sourcce code of the command.
db.sample.remove({}):- this will delete all docs in the collection, but still exist in the catlog.
db.system.namespace.find()
db.sample.drop()
use admin
db.runCommand({listDatabases:1})
Commands List:-
Server side:-
isMaster
serverStatus
logout
getLastError
DB Side:--
dropdatabase
repair database
clone
copydb
dbstats
--------------------------------------------------------------------------------
collection commands:-
DBA----------
create
drop
collstats
renamecollection
user----------
count
aggregate
mapreduce
findAndModify
---------------------------------------------------------------------------------
Index Commands:---
ensureindex
dropindex
db.products.save({_id:ObjectId("507d95d5719dbef170f15c00")},{$inc:{term_year:1}})
db.products.save({_id:ObjectId("507d95d5719dbef170f15c00")},{$set:{limits.sms.over_rate:0.01}})
Will Be adding few more in coming days
2. mongo:- connecting to DB
3. use pcat:- create new DB & switch to specific DB
4. db:- show current db in use
5. db.stats:- shows current DB useage information
6. show dbs:- shows dbs that avaliable.
7. show collections:- show the records created inside the DB.
8. db.sample.insert({a:1,b:"a string",someOthersfeild:22.34})
9. db.sample.find()
10. db.sample.find().pretty()
11. db.sample.find().toArray()
12. var x = db.sample.find().toArray()
13. db.getLastError()
14. db.sample.update({_id:99},{"_id":99,"p":14})
15. db.sample.findOne()
16. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$set:{E_ID:1110}}) :- this will do partial update of the document by only updating the E_ID value.
17. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$inc:{E_ID:1}}) :- This will increment the E_ID value by 1 i.e E_ID :1111
18. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$push:{Dig:"Sr.PL"}}) :- This will insert a new array to the document. and array will keep on increasing if needed.
19. db.sample.update({_id:ObjectId("57b2ff4cba66720291ffe0cc")},{$addToSet:{Dig:"Sr.PL"}}) :- This will insert a record onle if didn't exist.
20. db.sample.find({_id:100}):- this will display the only document in the collections for given that matchs the _id.
21. db.sample.find({_id:100}).count() :- This will display the count of document exist with given _id.
22. db.sample.remove({_id:100}) :- This remove the document from the collection for given _id.
23. db.sample.remove({}) :- this will remove all documents in the given "sample" collection.
24. db.sample.remove({x:/ra/})
24. mongoimport -d pcat -c test2 test.json :- this import the data from the file. pcat is a DB, test.json is a dbfile, test2 is collection.
Multiple documents update
25. db.sample.update({Order_id:12345},{name:raj},[false,[false]]) :-
26. db.users.update({_id: "Jane"}, {$addToSet: {likes: "football"}}, {upsert: true})
---------------------------------------------------------------------------------------------------------------
Buld Write Operations:-
var bulk = db.items.initializeUnorederedBulkOp();
db.items.find()
bulk.insert({item:"abcd",Qty:230,stats:"A",point:100})
db.items.find()
bulk.execute()
var b = db.items.initializeOrederedBulkOp();
b.find({item:"abcd"}).remove()
b.find.({item:"ijk123"}).update({$inc:{points:1}})
b.execute()
----------------------------------------------------------------------------------------------------------------
Commands:-
DBA Commands::
drop()
create()
compact()
serverStatus()
replSetGetStatus()
addShard()
User Comands::
aggregate()
MapReduce()
count()
FindAndModify()
getLastError()
isMaster()
help
db.runCommand({isMaster:1})
db.runCommand({isMaster})
db.isMaster()
db.isMaster:- this will give sourcce code of the command.
db.sample.remove({}):- this will delete all docs in the collection, but still exist in the catlog.
db.system.namespace.find()
db.sample.drop()
use admin
db.runCommand({listDatabases:1})
Commands List:-
Server side:-
isMaster
serverStatus
logout
getLastError
DB Side:--
dropdatabase
repair database
clone
copydb
dbstats
--------------------------------------------------------------------------------
collection commands:-
DBA----------
create
drop
collstats
renamecollection
user----------
count
aggregate
mapreduce
findAndModify
---------------------------------------------------------------------------------
Index Commands:---
ensureindex
dropindex
db.products.save({_id:ObjectId("507d95d5719dbef170f15c00")},{$inc:{term_year:1}})
db.products.save({_id:ObjectId("507d95d5719dbef170f15c00")},{$set:{limits.sms.over_rate:0.01}})
Will Be adding few more in coming days
No comments:
Post a Comment