MongoDB 101
Terms:
Database holds the collections
Collection holds the documents
Document is JSON formatted key/value pairs
Install/Start Mongo:
download and extract to your fav location
set ENV variable, export PATH=”~/Documents/Tools/mongodb/bin:$PATH”
Create a data directory under ~/data/db (default is /data/db, need to do sudo)
then start, “mongod –dbpath ~/data/db”
Create a new DB,
“use myDB”
show databases:
current: “db”
all: “show dbs”
Add User:
Insert/Update:
insert() will insert the document in myCollection.
save() will insert or update the document in myCollection based on _id field.
If myCollection doesn’t exists it will be created on first insert.
Select/find:
db.myCollection.find() will return all the available docs of myCollection.
can use field and logics in the find() functon.
For example,