Sunday, February 22, 2015

intro to MongoDB





Installation
Update homebrew:
$brew update
Install MongoDB binaries:
$brew install mongodb
Run MongoDB
$sudo mkdir -p /data/db //enter password
Start:
$sudo mongod
Remove:
$brew uninstall mongodb

Start Mongo:
$mongo

$show dbs
http://docs.mongodb.org/manual/reference/mongo-shell/


Reference:
http://docs.mongodb.org/manual/reference/program/mongod/#bin.mongod
https://www.youtube.com/watch?v=_rAPWkRqOP4
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

See Mongo data, insert, update, remove, find:
1. Open terminal and type below commands
$mongo
$shows dbs
$use NameOfDBs
$show collections
>users
$db.users.find()



Commands:

Query commands reference:
Examples:

Insert
> db.users.insert({"age" : "333", "firstName" : "iOS", "lastName" : "testing", "active" : true })

Update
> db.users.update({lastName: "Doe"})

Delete
> db.users.remove({lastName: "Doe"})

Find
> db.users.find({lastName: "11"})

> db.users.find({lastName: "11"})
{ "_id" : ObjectId("54ea92ce5d479d97c791df10"), "age" : 21, "firstName" : "Andres", "lastName" : "11", "active" : true }
{ "_id" : ObjectId("54ead8235d479d97c791df11"), "age" : 21, "firstName" : "Nico", "lastName" : "11", "active" : true }
{ "_id" : ObjectId("54efed3eb293b0b6d0aa208d"), "age" : 21, "firstName" : "Marco", "lastName" : "11", "active" : true }



Kill MongoDB:
1. Open terminal and type below commands
$pgrep mongo
584
$kill 584
Refrerence:
http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
Done :)

No comments:

Post a Comment