Mongod vs MongoDB server running as windows service - mongodb

I am trying to find out what is the difference when i start mongod db with mongod command vs starting mongo db server as a windows service.
I tried starting the server using mongod and inserted some records then i tried starting mongo db via windows service and inserted some records, results are different in the same database

You are using two different databases.
And you likely checked the "install mongod as a service" in the installation.
The mongod command directory is, by default, C:\data\db.
If you setup your mongod Windows service directory to any other directory, this means you potentially have two databases (data folder).
You can search for the file named mongod.lock. If you find the file on different directory. you have more than one mongo database.

Related

Installation process in MongoDB database

installation error while starting my mongodb server..
Ensure the user executing mongod is the owner of the lock file
and has the appropriate permissions. Also make sure that another
mongod instance is not already running on the C:\\data\\db\\ directory
how to start a server in my windows mongodb version--6.0.3

How to start mongodb service for windows

How can I run my mongo db service on windows 10
I have downloaded mongo db. tried coping data files in required directories . Whenever I try start mongodb service from task manager->services it shows windows could not start mongo db service.
Here's the official documentation about how to install and run MonogDB in window. Link
Secondly this question is also asked before you can get help from here too.
If you already have installed MongoDB in your window OS and make sure you have set the environment variable for MongoDB.
To start MongoDB server - type 'mongod' in command prompt.
Start MongoDB server
To start client - type 'mongo' in command prompt.
Start MongoDB client

MongoDB - mongo command runs but mongod doesn't

I have a MEAN droplet on digital ocean and I've found that when I run the mongo command I connect to test successfully and have access to my other databases, but if I try to run the mongod command I get the following message:
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
How is this possible? I thought mongo was connecting to a specific instance of mongod.
I will create the /data/db folder, but I feel like I might just be ignoring another problem with setup configuration that has allowed this to happen.
/data/db will be the place you store your database data. After you created that folder, you can run mongod as normal.
The mongod is a command to start mongodb server. And mongo is a command line interface to make you community with mongodb server.
So you should start the server -> community with server.

Issue with persistent mongoDB data on EC2

I'm trying to store data in a mongoDB database on Amazon EC2. I'm using starcluster to configure and start the EC2 instance. I have an EBS volume mounted at /root/data. I installed mongoDB following the instructions here. When I log in to the EC2 instance I am able to type mongo, which brings me to the mongo shell with the test database. I have then added some data to a database, let's say database1, with various collections in it. When I exit the EC2 instance and terminate it, using starcluster terminate mycluster, and then create a new, different instance, the database1 data is no longer shown in the mongo shell.
I have tried changing the dbpath in the /etc/mongodb.conf file to /root/data/mongodb, which is the EBS volume, and then start and stop the mongodb service using sudo service mongodb stop and sudo service mongodb start. I then try mongo again and receive
MongoDB shell version: 2.2.2
connecting to: test
Sat Jan 19 21:27:42 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
An additional issue is that whenever I terminate the EC2 instance any changes I made to the config file disappear.
So my basic question is: how do I change where mongoDB stores its data on EC2 so that the data will remain when I terminate one EC2 instance and then start another EC2 instance.
Edit:
In response to the first answer:
The directory does exist
I changed the owner to mongodb
I then issued the command sudo service mongodb stop
Checked to see if the port is released using netstat -anp | grep 27017. There was no output.
Restarted mongodb using sudo service mongodb start
Checked for port 27017 again and receive no output.
Tried to connect to the mongo shell and received the same error message.
Changed the mongodb.conf back to the original settings, restarted mongodb as in the above steps, and tried to connect again. Same error.
The EBS volume is configured in the starcluster config to be reattached on each startup.
For the "connect failed" after you change /etc/mongodb.conf problem, you can check the log file specified in the /etc/mongodb.conf (probably at /var/log/mongodb/mongodb.log):
Check that the directory specified by dbpath exists.
Make sure it is writable by the "mongodb" user. Perhaps it's best to chown to mongodb.
Make sure mongod actually released the 27017 port before starting it using: netstat -anp | grep 27017
Wait a couple seconds for mongod to restart before launching mongo.
It's not clear from your question if you are using Starcluster EBS volumes for Persistent Storage. Note that Ordinary EBS volumes do not automatically persist and reattach when you terminate an instance and start another. You would need to attach and mount them manually.
Once you get that working you'll probably want to create a custom Starcluster AMI with mongo properly installed and /etc/mongodb.conf appropriately modified.

Creating a database in Mongo: can't connect, get "connect failed"

I want to create a new database in Mongo. However, I'm having trouble connecting:
:~$ mongo
MongoDB shell version: 1.6.5
connecting to: test
Tue Dec 21 18:16:25 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed
How can I connect to mongo in order to create a new database? Alternatively, can I create a new database from the command line?
Slightly surprisingly, the Mongo docs don't seem to cover how to create a database.
Thanks.
In order to open Mongo JavaScript shell, a Listener should be initialized first.
So, first run mongod.exe before running mongo.exe. Both are in the same location(/bin).
There is no separate commands to create a db in mongodb. Just type "use dbname;" in console. Now you have created a db of the name 'dbname'. Now, if you type 'show databases' you cannot see the db name you just created. Because, mongo will not create any db, util you create collection and insert a document into that collection.
Hope this is useful to you!
cd /var/lib/mongodb/
remove mongod.lock file from this folder
sudo start mongodb (in console)
mongo (in console)
And it runs fine.
First you'll need to run mongod on one terminal. Then fire up another terminal and type mongo. This shall open the mongo shell. You also need to create /data/db/ where mongo will store your databases.
You'll need to run mongod (the daemon) before you can use mongo (the client), it's easiest to just run it in another shell; These should be in your path if mongo is installed correctly. After that the docs should get you through creating and editing dbs and collections.
Just try following commands in given order :
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb start
sudo service mongodb status