GSto
GSto

Reputation: 42350

Setting up MongoDB and Node.js on Ubuntu

I am try to set up an environment using Node.js and MongoDB on an installation of ubuntu. I am able to start a mongo database shell by running the mongo command. But I am unsure of how to accomplish a couple things.

I have the mongoose package installed, but I am still confused on how to connect to a particular database with it.

Upvotes: 0

Views: 1321

Answers (1)

Gates VP
Gates VP

Reputation: 45277

How do I set up MongoDB to run persistently, so that I can connect to it?

Depends on how you installed the MongoDB.

If you used the whole apt-get installation process, it generally installs an init.d script and the whole thing just runs with the default settings.

Try a ps -ef | grep mongod to look for the mongod process.

If you "installed" by downloading the tar file, then take a look at using upstart or similar process for making it run persistently. You'll want to use config files.

How do I connect to a certain MongoDB database from within Node.js once it is up and running?

Based on the Mongoose page, here is the basic connection process:

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database');

The standard connection string format is detailed here. Note that in my experience, not all drivers support all of the connection string features equally well, so do test your configuration.

Upvotes: 2

Related Questions