Setup And Running MongoDB [duplicate] - mongodb

This question already has answers here:
Mongod complains that there is no /data/db folder
(28 answers)
Closed 8 years ago.
I am using MongoDB on OSX. I am following along with a book.
MongoDB: The Definitive Guide, Second Edition
I have MongoDB installed and running. I have made a few collections with some values in them.
I installed using Homebrew
When I run mongo in the terminal my shell starts and I can use it fine.
When I run mongod I get an error stating a do not have a data/db directory. I know this is because the default location for mongo to store data is inside that directory but homebrew sets its own path up.
When I run
Home:~ ThisIsMe$ mongo
MongoDB shell version: 2.6.3
connecting to: test
> db.serverCmdLineOpts()
{
"argv" : [
"/usr/local/opt/mongodb/bin/mongod",
"--config",
"/usr/local/etc/mongod.conf"
],
"parsed" : {
"config" : "/usr/local/etc/mongod.conf",
"net" : {
"bindIp" : "127.0.0.1"
},
"storage" : {
"dbPath" : "/usr/local/var/mongodb"
},
"systemLog" : {
"destination" : "file",
"logAppend" : true,
"path" : "/usr/local/var/log/mongodb/mongo.log"
}
},
"ok" : 1
}
>
I get those file paths where homebrew set my mongo up at.
I want to make sure everything is set up correctly. Do I need to add something else to be able to run mongod without errors? I am under the impression I should be able to run mongod then go to http://localhost:28017/ to see information about my mongo.
But I cannot get mongod to run without the errors about data/db
Home:~ ThisIsMe$ mongod
mongod --help for help and startup options
2014-07-24T13:09:07.817-0500 [initandlisten] MongoDB starting : pid=1668 port=27017 dbpath=/data/db 64-bit host=NichoDiaz
2014-07-24T13:09:07.817-0500 [initandlisten]
2014-07-24T13:09:07.817-0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2014-07-24T13:09:07.817-0500 [initandlisten] db version v2.6.3
2014-07-24T13:09:07.817-0500 [initandlisten] git version: nogitversion
2014-07-24T13:09:07.817-0500 [initandlisten] build info: Darwin minimavericks.local 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2014-07-24T13:09:07.818-0500 [initandlisten] allocator: tcmalloc
2014-07-24T13:09:07.818-0500 [initandlisten] options: {}
2014-07-24T13:09:07.818-0500 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2014-07-24T13:09:07.818-0500 [initandlisten] dbexit:
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: going to close listening sockets...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: going to flush diaglog...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: going to close sockets...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: waiting for fs preallocator...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: lock for final commit...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: final commit...
2014-07-24T13:09:07.818-0500 [initandlisten] shutdown: closing all files...
2014-07-24T13:09:07.818-0500 [initandlisten] closeAllFiles() finished
2014-07-24T13:09:07.818-0500 [initandlisten] dbexit: really exiting now
Home:~ ThisIsMe$

It's there in the error message:
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
You need to create the /data and /data/db directories and make certain that the user running mongod can write to both of those directories. That's where mongod is going to write your database data. It's not created by default. Alternatively you could create your data directory elsewhere and then pass it in using --dbpath.

Related

mongod src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp no file

I've really been all over StackOverflow on this and couldn't find a solution. I have uninstalled Homebrew and Mongo via, well, brew. Nothing seems to fix it. Any help would be much appreciated.
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] MongoDB starting : pid=7684 port=27017 dbpath=/data/db 64-bit host=Matts-MacBook-Pro.local
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] db version v3.4.6
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2l 25 May 2017
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] allocator: system
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] modules: none
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] build environment:
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] distarch: x86_64
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] target_arch: x86_64
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] options: {}
2017-08-03T20:29:40.018-0400 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-08-03T20:29:40.019-0400 E STORAGE [initandlisten] WiredTiger error (2) [1501806580:19955][7684:0x7fffbdc783c0], file:WiredTiger.wt, connection: /data/db/WiredTiger.wt: handle-open: open: No such file or directory
2017-08-03T20:29:40.029-0400 I - [initandlisten] Assertion: 28595:2: No such file or directory src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 269
2017-08-03T20:29:40.029-0400 I STORAGE [initandlisten] exception in initAndListen: 28595 2: No such file or directory, terminating
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-08-03T20:29:40.029-0400 I CONTROL [initandlisten] now exiting
2017-08-03T20:29:40.029-0400 I CONTROL [initandlisten] shutting down with code:100
I also have to spent more than 4 hours to find a solution you asked. In my case, the stack trace is same as in your case.
I used MongoDB 4.2. But I need to downgrade it to MongoDB 3.4. After downgrading to 3.4 above error can be seen. Then again I updated MongoDB to 4.2. Still there was that error.
Tried many solutions on Stack Overflow but nothing solved my issue. As my final option I run below command.
mongod --dbpath /data/db --repair
But it also did not work.
There were some files on my /data/db directory.
Those are WiredTiger, WiredTiger.lock, WiredTiger.turtle, diagnostic.data, journal and mongod.lock.
Removed all the files in /data/db directory.
rm -rf /data/db/*
Run above command with sudo if you are not the root user.
Then I run mongod --dbpath /data/db --repair command again.
Then I could start MongoDB successfully by running mongod --dbpath /data/db.
Do not forget add bin/mongod to PATH in .bash_profile(If you are using Mac).

MongoDB WiredTiger configuration

I am trying to install MongoDB on my local machine using the Wired Tiger storage engine and experiencing some issues. I downloaded the binaries and following the guide installed it to C:\MongoDB. This got installed using the default engine MMAPV1 but I want to change this to Wired Tiger. To do this I simply used the following command.
mongod.exe --storageEngine "wiredTiger" --dbpath "c:\mongodb\data\wt"
Should mention I have also installed the hotfix and still get the same issue.
It seems this command works as it creates a bunch of files in the specified folder above such as WiredTiger, storage.bson, WiredTiger.turtle etc.
PS C:\MongoDB\bin> .\mongod.exe --storageEngine "wiredTiger"
2015-09-02T15:07:41.266+0100 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
2015-09-02T15:07:41.270+0100 E NETWORK [initandlisten] listen(): bind() failed errno:10048 Only one usage of each socke
t address (protocol/network address/port) is normally permitted. for socket: 0.0.0.0:27017
2015-09-02T15:07:41.271+0100 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory C:\data\db\ not fo
und., terminating
2015-09-02T15:07:41.271+0100 I CONTROL [initandlisten] dbexit: rc: 100
PS C:\MongoDB\bin> .\mongod.exe --storageEngine "wiredTiger" --dbpath C:\MongoDB\data\wt
2015-09-02T15:10:38.844+0100 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
2015-09-02T15:10:38.847+0100 E NETWORK [initandlisten] listen(): bind() failed errno:10048 Only one usage of each socke
t address (protocol/network address/port) is normally permitted. for socket: 0.0.0.0:27017
2015-09-02T15:10:38.848+0100 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7G,session_max=20000,e
viction=(threads_max=4),statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(c
lose_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] MongoDB starting : pid=24296 port=27017 dbpath=C:\MongoDB\data\w
t 64-bit host=WSX-111-9999
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] db version v3.0.6
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, buil
d=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] allocator: tcmalloc
2015-09-02T15:10:39.055+0100 I CONTROL [initandlisten] options: { storage: { dbPath: "C:\MongoDB\data\wt", engine: "wir
edTiger" } }
2015-09-02T15:10:39.057+0100 I CONTROL [initandlisten] now exiting
2015-09-02T15:10:39.057+0100 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2015-09-02T15:10:39.057+0100 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2015-09-02T15:10:39.057+0100 I NETWORK [initandlisten] shutdown: going to close sockets...
2015-09-02T15:10:39.057+0100 I STORAGE [initandlisten] WiredTigerKVEngine shutting down
2015-09-02T15:10:39.074+0100 I STORAGE [initandlisten] shutdown: removing fs lock...
2015-09-02T15:10:39.075+0100 I CONTROL [initandlisten] dbexit: rc: 48
PS C:\MongoDB\bin> .\mongo.exe
2015-09-02T15:11:03.091+0100 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.0.6
connecting to: test
> db.serverStatus().storageEngine
{ "name" : "mmapv1" }
> exit
bye
PS C:\MongoDB\bin>
Any ideas why this isn't playing ball? I have installed this as a windows service which starts fine and also when using the shell and use the command
db.serverStatus().storageEngine
I get the value mmappv1 back.
Personally, for me to get this working I had to remove the service via the command: .\mongod.exe --remove followed by an install however this time specifying the storage engine etc. So the command becomes
.\mongod.exe --dbpath c:\mongodb\data\wt --logpath c:\mongodb\log\mongo.log --storageEngine wiredTiger --install
Enter the shell and use the command db.serverStatus().storageEngine the world suddenly becomes a happier place { "name" : "wiredTiger" }

MongoDB running locally but when trying to access remotely it failed

Able to run MongoDB locally but when trying to access remotely it failed. Havent done any firewall setup. What could be the issue? How to do troubleshoot?
Also the MongoDB status show running
service mongod status
mongod (pid 25342) is running...
But when trying to restart the service it says
service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [FAILED]
But still the process is running
Update
Tried mongod --repair here is the update
2015-01-10T10:46:33.109-0500 [initandlisten] MongoDB starting : pid=29018 port=2 7017 dbpath=/data/db 64-bit host=ns4008927.ip-192-99-3.net
2015-01-10T10:46:33.109-0500 [initandlisten] db version v2.6.6
2015-01-10T10:46:33.109-0500 [initandlisten] git version: 608e8bc319627693b04cc7 da29ecc300a5f45a1f
2015-01-10T10:46:33.109-0500 [initandlisten] build info: Linux build10.nj1.10gen .cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LI B_VERSION=1_49
2015-01-10T10:46:33.109-0500 [initandlisten] allocator: tcmalloc
2015-01-10T10:46:33.109-0500 [initandlisten] options: { repair: true }
2015-01-10T10:46:33.112-0500 [initandlisten] finished checking dbs
2015-01-10T10:46:33.112-0500 [initandlisten] dbexit:
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to close listening sockets...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to flush diaglog...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to close sockets...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: waiting for fs preallocat or...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: closing all files...
2015-01-10T10:46:33.112-0500 [initandlisten] closeAllFiles() finished
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: removing fs lock...
2015-01-10T10:46:33.112-0500 [initandlisten] dbexit: really exiting now
You need to remove this line from mongo's config file (on Ubuntu, mine is at /etc/mongod.conf):
bind_ip = 127.0.0.1
Or, if it's YAML,
bindIp: 127.0.0.1
Source: http://docs.mongodb.org/manual/reference/configuration-options/
"Changed in version 2.6.0: The deb and rpm packages include a default configuration file that sets net.bindIp to 127.0.0.1."
The default value for bindIp/bind_ip is "all interfaces" - so that's where the deletion comes in handy.

MongoDB --dbpath giving access to old data

I have mongo installed on my local machine. When I start the database by running mongod I got this error (that is fairly common, and this site has solutions to workarounds):
$ mongod
mongod --help for help and startup options
2015-01-01T22:31:17.350-0600 [initandlisten] MongoDB starting : pid=2835 port=27017 dbpath=/data/db 64-bit host=hermes
2015-01-01T22:31:17.351-0600 [initandlisten] db version v2.6.4
2015-01-01T22:31:17.351-0600 [initandlisten] git version: nogitversion
2015-01-01T22:31:17.351-0600 [initandlisten] build info: Darwin minimavericks.local 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2015-01-01T22:31:17.351-0600 [initandlisten] allocator: tcmalloc
2015-01-01T22:31:17.351-0600 [initandlisten] options: {}
2015-01-01T22:31:17.351-0600 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2015-01-01T22:31:17.351-0600 [initandlisten] dbexit:
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: going to close listening sockets...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: going to flush diaglog...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: going to close sockets...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: waiting for fs preallocator...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: lock for final commit...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: final commit...
2015-01-01T22:31:17.351-0600 [initandlisten] shutdown: closing all files...
2015-01-01T22:31:17.352-0600 [initandlisten] closeAllFiles() finished
2015-01-01T22:31:17.355-0600 [initandlisten] dbexit: really exiting now
I created a directory in my development environment at /my/curent/directory/data/db and started mongo again with $ mongod --dbpath /my/curent/directory/data/db, this time producing:
2015-01-01T22:32:31.282-0600 [initandlisten] options: { storage: { dbPath: "./data/db" } }
2015-01-01T22:32:31.319-0600 [initandlisten] journal dir=./data/db/journal
2015-01-01T22:32:31.320-0600 [initandlisten] recover : no journal files present, no recovery needed
2015-01-01T22:32:31.383-0600 [FileAllocator] allocating new datafile ./data/db/local.ns, filling with zeroes...
2015-01-01T22:32:31.383-0600 [FileAllocator] creating directory ./data/db/_tmp
2015-01-01T22:32:31.482-0600 [FileAllocator] done allocating datafile ./data/db/local.ns, size: 16MB, took 0.098 secs
2015-01-01T22:32:31.842-0600 [FileAllocator] allocating new datafile ./data/db/local.0, filling with zeroes...
2015-01-01T22:32:32.756-0600 [FileAllocator] done allocating datafile ./data/db/local.0, size: 64MB, took 0.914 secs
2015-01-01T22:32:33.215-0600 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2015-01-01T22:32:33.216-0600 [initandlisten] added index to empty collection
2015-01-01T22:32:33.216-0600 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0 reslen:37 1852ms
2015-01-01T22:32:33.216-0600 [initandlisten] waiting for connections on port 27017
2015-01-01T22:33:31.402-0600 [clientcursormon] mem (MB) res:33 virt:2635
2015-01-01T22:33:31.402-0600 [clientcursormon] mapped (incl journal view):160
2015-01-01T22:33:31.402-0600 [clientcursormon] connections:0
It's great. Using the mongo shell, I can access my collections that I was working with in this directory, but I can also see all of my other databases from weeks prior (when this directory did not exist) using show dbs. What purpose does the --dbpath option serve if not to isolate where data is stored? Is something weird happening here?
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db.
To use an alternate dbpath, specify the path in the configuration file (e.g. C:\Program Files\MongoDB\mongod.cfg) or on the command line with the --dbpath option.
Read more about MongoDB Installation
If you are using windows then create data\db folder under C drive.
If you are using your own directory for data then pass full path of the folder as --dbpath argument value.
If MongoDB’s default data directory path "\data\db" is correct but accessing old data means just check your Task Manager.
End all mongo command and restart your mongodb. I tried it, working well

Double MongoDb Version

Problem with MongoDB Version
I installed Mongo Db follow this Link
http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/
After i updated with Brew
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
mongod --help for help and startup options
2014-04-28T10:49:46.475+0200 [initandlisten] MongoDB starting : pid=2197 port=27017 dbpath=/data/db 64-bit host=Foo.local
2014-04-28T10:49:46.475+0200 [initandlisten]
2014-04-28T10:49:46.475+0200 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2014-04-28T10:49:46.475+0200 [initandlisten] db version v2.6.0
2014-04-28T10:49:46.475+0200 [initandlisten] git version: nogitversion
2014-04-28T10:49:46.475+0200 [initandlisten] build info: Darwin minimavericks.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2014-04-28T10:49:46.476+0200 [initandlisten] allocator: tcmalloc
2014-04-28T10:49:46.476+0200 [initandlisten] options: {}
2014-04-28T10:49:46.476+0200 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2014-04-28T10:49:46.476+0200 [initandlisten] dbexit:
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: going to close listening sockets...
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: going to flush diaglog...
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: going to close sockets...
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: waiting for fs preallocator...
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: lock for final commit...
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: final commit...
2014-04-28T10:49:46.476+0200 [initandlisten] shutdown: closing all files...
2014-04-28T10:49:46.477+0200 [initandlisten] closeAllFiles() finished
2014-04-28T10:49:46.477+0200 [initandlisten] shutdown: removing fs lock...
2014-04-28T10:49:46.477+0200 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
2014-04-28T10:49:46.477+0200 [initandlisten] dbexit: really exiting now
➜ ~ mongo --version
MongoDB shell version: 2.6.0
but if i do this:
> use foo
switched to db foo
> use foo
switched to db foo
> foo.version()
2.4.9
How can I clean my double Installation?
I want 2.6.0
#monkeyUser,
Running two different MongoDB instances is not an issue per-se provided they use different data directories. In your case, looks like you have two MongoDB installation with same data directory configured for both. If you intend to keep both the instances you'll need to change the dbPath for one of them to point at some other directory.
If you do not intend to run two instances and only the latest instance, uninstall the previously installed instance using same steps from the blog post but executing them in reverse order (bottom up) and in inverted sense i.e. if blog has a step to create a directory /data/db, you would execute this steps as "deleting the data directory /data/db". Once you have removed one of the instances, second instances should come up fine.