Unable to start/launch local mongo db

I'm new to MongoDB. I currently have a dump of a mongo db (i.e. directory of .bson files) and am trying to import that into mongo.

I installed mongo as per the instructions on http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/.

I'm currently trying to test starting a local mongo instance by running mongod --dbpath /path/to/my/mongodata (which is an empty directory).

I get the following in stdout:

Thu Sep 20 09:46:01 [initandlisten] MongoDB starting : pid=1065 port=27017 dbpath=/path/to/my/mongodata/ 64-bit host=dhcp-18-111-28-92.dyn.mit.edu
Thu Sep 20 09:46:01 [initandlisten]
Thu Sep 20 09:46:01 [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 266 processes, 2560 files. Number of processes should be at least 1280 : 0.5 times number of files.
Thu Sep 20 09:46:01 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Sep 20 09:46:01 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Sep 20 09:46:01 [initandlisten] build info: Darwin bs-osx-106-x86-64-1.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Thu Sep 20 09:46:01 [initandlisten] options: { dbpath: "/path/to/my/mongodata/" }
Thu Sep 20 09:46:01 [initandlisten] journal dir=/path/to/my/mongodata/journal
Thu Sep 20 09:46:01 [initandlisten] recover : no journal files present, no recovery needed
Thu Sep 20 09:46:01 [websvr] admin web console waiting for connections on port 28017
Thu Sep 20 09:46:01 [initandlisten] waiting for connections on port 27017

At this point, it just hangs there and does nothing. Seems like it's waiting for something to happen on localhost, but I don't know mongo well enough to understand what's going on. Any help?

74542 次浏览

There is nothing wrong, you have started the server, it is running and listening on port 27017. Now you can start to interact with the server, for example just open a new terminal tab and run mongo ,which will open mongo's interactive console and connects to the default server(localhost:27017)

If you want to run mongod as a background process (to get back the console) you can use --fork command option. This requires you to use some sort of logging.

Eg. mongod --dbpath /path/to/my/mongodata --fork --logpath /path/to/my/mongod.log

If you want to restore a bsonexport you will probably use the mongorestore command

Add the below in the configuration file and call it using monogd, make sure your bind_ip is configured as per your requirement and use the below link to add few more replica sets:

https://docs.mongodb.org/manual/tutorial/deploy-replica-set/

Step 1:

vi /etc/mongod.conf


replication: replSetName: rs01

Step 2:

mongod --config /etc/mongod.conf

产量:

warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
about to fork child process, waiting until server is ready for connections.
forked process: 30012
child process started successfully, parent exiting

pressing ctrl+c or ctrl+z will stop mongod service,and just run sudo servie mongod start

You need to follow the below 2 steps:

Step 1: Open CMD and enter mongod. This will run the mongo server

Step 2: Open another Command Prompt, move to the location of file and type

mongorestore -d db_name -c collection_name file.bson

Copied from official documentation

This starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/