NodeJS Mongo Basic


Install in Mac OS X

Install with homebrew

It’s easy way to install mongodb

Basic Operation using mongo

mongo is client application to manipulate

Start mongodb

mongod --dbpath ./data

You need to make data directory. data is data space.
By executing this command, mongod process starts

Connect database


mongo is client command

Show database list

show dbs

Switch database

use mydb

mydb is database name.

Check db object


Check db object to connect successfully

Show collection list

collection is like table of database
That is, data collection name

show collections

Save data

Insert data into collection{name:'yoona', mail:'',memo:'this is test'})

Show data



{ “_id” : ObjectId(“54cc31d54a29d4a4ab3307b4”), “name” : “yoona”, “mail” : “”, “memo” : “this is test” }

where clause


Regular expression


Add condition

db.mydata.find({name:/oo/, mail:''})

MongoDB nodejs

mongodb : MongoDB driver
Mongoose : Modeling tool library

With Express

  "express": "3.2.6",
  "jade": "*",
  "mongoose": "3.x"

npm install(with Eclipse)
Point “package.json” -> Run As -> npm install

Before starting application, you need to start mongod program.

※ We need some steps to use mongoose in Mac OS X
This is great post about it.

Delete mongoose folder and npm install again

npm install