Problem with choosing a folder to store collections and database - mongodb

I got a error with mongod -- dbpath
My command in mongo shell:
mongod --dbpath C:\BooksData
Answer:
[js] SyntaxError: missing ; before statement #(shell):1:9

Related

How do I connect to mongodb on MacOS after adding configurations for replica set?

I want to tail mongo collection's documents and in order to do so, I need to activate the oplog. Oplog requires some extra configuration in the mongod.conf file and these configurations are not letting mongo connected.
I tried to look into questions pertaining to tailing mongodb, setting conf file but none could address my need of connecting to mongodb after setting replciaset configs.
My conf file, location of which is /usr/local/etc/mongod.conf is:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
replSet=rs0
oplogSize=1024
I am not getting anything in logs, brew services list command also shows the following:
mongodb started aviralsrivastava /Users/aviralsrivastava/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Although, when rs0 is set, the started signal is yellow in color, with the last two lines commented, its green.
I expect mongodb to get connected, mongo shell to start but all I get is connection refused. If I comment the last two lines, mongo gets connected. And yes, I did restart mongodb via brew services restart mongodb each time I changed the config file.
Following is the error when I try to connect via command mongodb:
➜ etc mongo
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
2019-04-27T08:53:31.350+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:257:13
#(connect):1:6
exception: connect failed
mongod --config path/to/config-file-portx --replSet rsName
connect:
mongo --port xxx
config:
config:
rs.initialize();
rs.add(host:port-y);
rs.status()
connect with replica:
mongo "mongodb://host1,host2,host3/myDB?replicaSet=rsName"

How the lock file is shared among the various mongods

I am trying to setup a shard and replica set.
My assumption procedure be like this :
Start a replica set (let it be only one, just for testing)
mongo then initiate replica
Start a config server (again let it be one, just for testing)
Start a shard server (again let that be just one)
Add the shard and enable sharding via mongo
What i did :
mongod --replSet rs0 --dbpath data/rs0-0 --unixSocketPrefix data/rs0-0
mongo then rs.initiate()
mongod --configsvr --dbpath data/rs0-0 --unixSocketPrefix data/rs0-0
-- now stucked at step 3.
Error i find is
2017-05-22T20:00:13.857+0530 [initandlisten] exception in initAndListen: 10310 Unable to lock file: data/rs0-0/mongod.lock. Is a mongod instance already running?, terminating
What i have tried :
i have tried with different directories for --unixSocketPrefix options, but each time it hits data/rs0-0/mongod.lock the same file. So it did not worked
It seems simple issue but unable to figure out how the lock file is shared among the various mongods (whether it be config server, or replica set, or shard server)
I am on mongodb 2.6.12
You need to start mongod and config server with different dbpath options.
You can follow the following steps:
mongod --replSet rs0 --dbpath data/rs0-0 --unixSocketPrefix data/rs0-0
or
mongod --replSet rs0 --dbpath data/rs0-0
mongo then rs.initiate()
mkdir -p /data/configdb (grant required permission recursively)
mongod --configsvr --dbpath /data/configdb --port 27019

Can't set a db path?

I've installed mongodb on my mac using homebrew using the following command in terminal:
brew services start mongodb
However when I try to set the db path, I get the following error:
mongod --dbpath
2017-02-24T09:49:08.874+0000 E QUERY [thread1] SyntaxError: missing ; before statement #(shell):1:9
What am I doing wrong?
Thanks
You can run this comming in your command promt or can set this path in mongo.conf file what should work for you.
sudo mongod --port 27017 --dbpath /var/lib/mongodb

Mongodb problem_could not connect to server

I use ubuntu 14.04LTS and with mongodb version 2.4.9.When I type "mongo" in terminal, it always show "connecting to: test
Tue Jun 3 10:03:57.911 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed".
But if i run mongod in one terminal, and run mongo in another, all is ok.
If I close the window of mongod, the connection fail again.
I need to use mongodb without open a terminal of mongod, how can I do with it ?
Thank you!
You need to start mongodb as a service or daemon(depending on the OS,in your case daemon), check the documentation
Documentation
sudo service mongod start
Or
To run a mongod process as a daemon (i.e. fork), and write its output to a log file, use the --fork and --logpath options. You must create the log directory; however, mongod will create the log file if it does not exist.
The following command starts mongod as a daemon and records log output to /var/log/mongodb.log.
mongod --fork --logpath /var/log/mongodb.log

installation error on mongo DB

I installed MongoDB on ubuntu 11.04 followed by this site. I gave this command to run MongoDB
sudo /etc/init.d/mongodb start
It showed some error like this
sudo: /etc/init.d/mongodb: command not found
I checked the file.But it was okay.Can any one tell me how to solve this.
Please help me .I am newbie to mongoDB.
[edited] When I am connecting to mongo it is showing error like
connecting to: test
Sun Jul 3 09:57:29 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
You may should try to run:
mongo --nodb
This worked for me.
Regarding to the connection error, you can try:
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
This starts the daemon using the config file /etc/mongodb.conf and repair the database.
Then start the database:
sudo -u mongodb mongod -f /etc/mongodb.conf