Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS + MongoDB - Starting mongodb server instance installed from npm

I'm running node.js on OSX and have just installed mongodb using command npm install mongodb under myapp/node_modules directory. According to mongodb official documenation, to start a mongodb you just have to execute ./mongodb/bin/mongo on the command line. However I didn't see any directory called 'bin' under the node_modules/mongodb..

Is there a special way to start a mongodb instance when it were bundled together with a node.js app? How would I start a mongodb server running on mongodb://localhost/myapp?

I'm currently also using matador (new mvc framework for node), and according to the documentation, we connect to the mongodb server this way:

// app/models/ApplicationModel.js
module.exports = require('./BaseModel').extend(function () {
  this.mongo = require('mongodb') 
  this.mongoose = require('mongoose')
  this.Schema = this.mongoose.Schema
  this.mongoose.connect('mongodb://localhost/myapp') //CONNECT TO MONGODB SERVER...
})

At this moment I dont think I have mongodb server running, and don't really know how to set it up because of the issue above. Would appreciate any links, answers, and pointers to the right direction. Thanks!

like image 614
Benny Tjia Avatar asked Jan 09 '12 00:01

Benny Tjia


People also ask

How do I know if MongoDB is connected NodeJS?

The following example demonstrates connecting to the local MongoDB database. var MongoClient = require('mongodb'). MongoClient; // Connect to the db MongoClient. connect("mongodb://localhost:27017/MyDb", function (err, db) { if(err) throw err; //Write databse Insert/Update/Query code here.. });


1 Answers

npm install mongodb is the command for installing Node.js driver for MongoDB. You'll have to install MongoDB server separately.

You can get it here: http://www.mongodb.org/downloads

like image 101
Sergio Tulentsev Avatar answered Oct 13 '22 00:10

Sergio Tulentsev