-
Notifications
You must be signed in to change notification settings - Fork 113
Home
- Q: The data directory not found or permission denied
- Q: WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
- Q: mongod waiting for connections on port 27017
- Q: Error connecting to db server: no reachable servers
- Q: NameError: uninitialized constant Mongo::Client
- Q: Hash Rocket Notation vs. JSON Notation
A: Creating the data directory C:\data\db
(windows) or /data/db
(linux)
In windows:
C:\>mkdir -p C:\data\db
In Linx or Mac, as root
user:
$ mkdir -p /data/db
$ chown -R mongod:mongod /data/db
Otherwise:
$ sudo mkdir -p /data/db
$ sudo chown -R mongod:mongod /data/db
See also:
- mongodb Mongod complains that there is no /data/db folder
- MongoDB Setup - Data Directory Not Found or Permission Denied
After installing and running the mongo server,
$ mongod
Then in a another terminal, when running the mongo client,
$ mongo
The following warnings are shown:
Server has startup warnings:
2016-01-19T20:59:55.320-0800 I CONTROL [initandlisten]
2016-01-19T20:59:55.320-0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
What to do?
A: In Linux, set the resource limit just before starting mongod
with this:
$ ulimit -n 1024
$ mongod
After doing mongod
it shows:
[initandlisten] waiting for connections on port 27017
In the video a connection was accepted, that line is missing on my computer. Is this a problem?
A: No, this is not a problem. That was probably because a client running was already running in the video.
When you start clean, mongod
should just come and wait for connections. This is the MongoDB database server.
When you start mongo
then you should see the connection accepted message since this is the client connecting to the database server.
This error shows up when try to run mongoimport
:
mongoimport --db test --collection zips --drop --file zips.json
A: This happens if MongoDB Server (mongod
) is not running.
In a different terminal, go ahead and start mongod and then do an import.
In irb,
rb(main):001:0> require 'mongo'
=> true
irb(main):002:0> db = Mongo::Client.new('mongodb://localhost:27017')
NameError: uninitialized constant Mongo::Client
from (irb):2
...
A: This error is because the `mongo`` ruby driver was not loaded properly.
First in the command shell ensure that you have installed the ruby gems by running:
C:\>gem install mongo
C:\>gem install bson_ext
Now start irb and run the command:
C:\>irb
irb(main):001:0> require 'mongo'
=> true
irb(main):004:0> db = Mongo::Client.new('mongodb://localhost:27017')
D, [2016-01-23T09:33:16.963650 #4156] DEBUG -- : MONGODB | Adding localhost:27017 to the cluster.
=> #<Mongo::Client:0x24416640 cluster=localhost:27017>
Is there any particular reason for choosing to use the :symbol => "value"`` (Hash Rocket) notation or
symbol: "value"` (JSON) notation?
A: The GitHub Ruby style guide suggests just to use the hash-rocket syntax for Hash literals and Rails style guide prefers JSON.
So it really comes down to your preference and in which side of the fence you are on.
See also:
- [GitHub Ruby Style Guide] (https://github.com/styleguide/ruby)
- Rails coding style conventions
- Is Hash Rocket deprecated?