-
Notifications
You must be signed in to change notification settings - Fork 113
Home
If you have have a general question that is not specific to the Module 1 content, it may have already been answered here.
- 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
- Q: Submission is failing because of directory structure
- Q: Unexpected nil error
A: Create 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?
I'm seeing the error:
Application not found in root directory of archive. This may be an invalid archive format or application scoped below an extra directory.
How can I fix this?
A: You need to fix the directory structure of your submission. The Gemfile
, the app directory, etc. need to be in the root of your zip, not in a folder. Let's say your app, Gemfile, etc. are in the my_project directory. You can ensure your zip is structured correctly, you can run the following commands:
cd my_project
zip -r my_project.zip .
In plain English, the zip
command means zip the contents of my current directory (i.e. the .
) recursively (the -r
) and name it my_project.zip
.
I'm seeing a failing unit test where a value is expected to be not nil, but it is nil. How can I fix this?
A: One of the things you can check is whether there's a mismatch with your hash keys.
When implementing a method that takes a hash, be sure to account for the inputs being either string keys or symbol keys.
- use
to_s
when you know you are going to compare to a String - use
to_sym
when you know you are going to compare to a symbol
Within Rails you can also:
- use
stringify_keys
,stringify_keys!
,deep_stringify_keys
, anddeep_stringify_keys!
to convert all keys of a Hash to Strings to assure you that you are working with Strings. - use
symbolize_keys
andsymbolize_keys!
,deep_symbolize_keys
anddeep_symbolize_keys!
to convert all keys of a Hash to Symbols to assure you are working with Symbols.
This specifically was encountered during the scaffold_spec.rb
tests for Course #3, Module 1, summative assignment when the Racer.initalize()
method was written to process String keys and not Symbol keys for the input has. This resulted in capybara inserting an empty document into the database and the test unable to locate the document using a first_name and last_name search.