Tag Archives: mongodb

mongo dump

Say you want to do a dump of your mongo database onto your desktop.

You’d go:


mongodump -d DumpFolderName -o /location/of/your/directory

mongodump1

Once it makes a dump, you’ll see the DumpFolderName folder with various files in there. It contains the data of your database.

mongodump3

When you want to make the restore, copy the DumpFolderName to that machine. Make sure MongoDB is installed. Then just type


mongorestore DumpFolderName

mongodump2

MongoError: connect ECONNREFUSED

If you start up your node project (given that it uses mongo to connect to some database) without starting up your mongo db, you’ll get errors.

For example:
Rickys-MacBook-Pro:TODO_url_authentication rickytsao$ gulp
[22:02:09] Using gulpfile ~/Desktop/TODO_url_authentication/gulpfile.js
[22:02:09] Starting ‘default’…
[22:02:09] Finished ‘default’ after 2.12 ms
[22:02:09] [nodemon] v1.3.7
[22:02:09] [nodemon] to restart at any time, enter rs
[22:02:09] [nodemon] watching: *.*
[22:02:09] [nodemon] starting node server.js
Magic happens at http://localhost:8080
connection error: { [MongoError: connect ECONNREFUSED] name: ‘MongoError’, message: ‘connect ECONNREFUSED’ }

Simply open up another terminal and type in:
mongod
Then the database will start up and you’ll see whole bunch of logs…

2015-07-05T22:05:14.166+0800 W – [initandlisten] Detected unclean shutdown – /data/db/mongod.lock is not empty.
2015-07-05T22:05:14.182+0800 I JOURNAL [initandlisten] journal dir=/data/db/journal
2015-07-05T22:05:14.182+0800 I JOURNAL [initandlisten] recover begin
2015-07-05T22:05:14.187+0800 I JOURNAL [initandlisten] recover lsn: 29046914
2015-07-05T22:05:14.187+0800 I JOURNAL [initandlisten] recover /data/db/journal/j._0
2015-07-05T22:05:14.188+0800 I JOURNAL [initandlisten] recover skipping application of section seq:0 < lsn:29046914 2015-07-05T22:05:14.189+0800 I JOURNAL [initandlisten] recover skipping application of section seq:15301820 < lsn:29046914 2015-07-05T22:05:14.224+0800 I JOURNAL [initandlisten] recover cleaning up 2015-07-05T22:05:14.224+0800 I JOURNAL [initandlisten] removeJournalFiles 2015-07-05T22:05:14.252+0800 I JOURNAL [initandlisten] recover done 2015-07-05T22:05:14.297+0800 I JOURNAL [durability] Durability thread st

custom collection name

pass the collectionName as the third argument

OR

var UserInfo = new Schema({
username : String,
password : String
}, { collection: ‘userinfo’ });