mongo //Start mongo shell
show dbs //Display databases
use mydb //Start using 'mydb' database
db //Display current database
show collections //Display collections
help //help
Create and insert a document into the collection "testData"
j = { name : "mongo" }
db.testData.insert( j )
// or you can
db.testData.insert({ name : "mongo" })
save a data
db.products.save( { name: "kevin", age: 40 } )
db.products.save( { name: "kevin", age: 40 }, { name: "colin", age: 45 } )
Retrieve data from dataabse
db.testData.find() //Retrieve all data in the collection "testData"
db.testData.findOne() //Retrieve the first data found
db.testData.find({"name": "kevin"}) //Retrieve the specific data (name field is equal to "kevin")
db.testData.find().limit(3) //Retrieve the data limited to 3 documents
Remove data
db.testData.remove({}) //Remove all data from this collection
db.testData.remove({"name": "kevin"}) //Remove the data which has name "kevin"