Mongodb - Difference between running “mongo” and “mongod” databases

后端 未结 3 1301
悲&欢浪女
悲&欢浪女 2020-12-12 12:39

So, I\'m sure I\'m missing something simple here, but when I run mongo as a daemon (using mongod --fork or just mongod), I see different database content than if I just run

3条回答
  •  粉色の甜心
    2020-12-12 12:52

    I think there is some confusion here.

    mongod is the "Mongo Daemon" it's basically the host process for the database. When you start mongod you're basically saying "start the MongoDB process and run it in the background". mongod has several default parameters, such as storing data in /data/db and running on port 27017.

    mongo is the command-line shell that connects to a specific instance of mongod. When you run mongo with no parameters it defaults to connecting to the localhost on port 27017. If you run mongo against an invalid machine:port combination then it will fail to connect (and tell you as much).

    Ideally, when doing anything other than just "playing around", you'll use the Command Line Parameters for starting mongod. By the same measure you should start the mongo shell with explicit instructions.

    Based on your description, I think you may be encountering an issue regarding the use of default databases. Try starting mongo with the following (where dbname is your database name)

    ./mongo localhost:27017/dbname
    

提交回复
热议问题