mongoDB Atlas ♥︎ Sailsjs (waterline sails-mongo adapter) - mongodb

i just created a MongoDB Atlas account.
I'm using sails with waterline sails-mongo adapter
but I can't manage to connect via my app.
Everything is up to date.
I can connect to any other DB (localhost, digitalocean server, ...)
I can also connect to that MongoDB Atlas Database via their tool (MongoDB Compass) and via shell with the mongo cmd
but it seems like sails-mongo is just not working with that db, which requires a very up-to-date mongo version
Is someone else using MDB Atlas && sailsjs ?
(I thought about refactoring my app, but it's starting to be huuge and it just seems impossible to use the "mongodb" adapter)
Versions :
- node : 6.3.1
- npm : 3.10.6
- mongo (shell) : 3.4.2
- sails-mongo npm module : sails-mongo#0.12.2

Hey people thanks to your tips and SailsJS team I was able to figure out a few things that can help you fix this issue (I was able to):
Update your sails-mongo to v0.12.3 npm install sails-mongo#0.12.3 --save
Update sails-mongo's mongodb dependency to v2.2.25. You can do this editing package.json. That version includes a fix for replicaSets connections: https://github.com/mongodb/node-mongodb-native/commit/915d5c8a765151fb14942445a92d92a0e9e9c942#diff-88dc7475eedf918122374be6d7c2c151R12
Make sure that the mongodb's mongodb-core version is at least v2.1.9.
Now I went directly and created my connection like this:
{
adapter: 'sails-mongo',
url: 'mongodb://user:pass#server-1.mongodb.net:27017,server-2.mongodb.net:27017,server-3.mongodb.net:27017/test?ssl=true&replicaSet=server-&authSource=admin',
ssl: true
}
Yes, you need to add the ssl parameter again.
By looking at the sails v1.0 code, lost of this things will be fixed by that update ;) Thanks SailsJS Team!

it seems like sails-mongo is just not working with that db, which requires a very up-to-date mongo version
You hit the nail on the head -- the current sails-mongo adapter for Sails v0.12.x uses a version of the native MongoDB driver that doesn't support all the features required to work with Atlas (e.g. authSource). See this issue on Github.
We're finishing up the last bits on the sails-mongo adapter for Sails 1.0, which supports the latest options and has been tested successfully with Atlas, so now might be a good time to start preparing to upgrade to version 1.0. After Sails 1.0 is released we'll only be doing bug fixes and security patches to modules that work with v0.12.x.

The error message suggests that the connection is timing out. Step one would be to check your configuration, is it correctly populated with this format in config/connections.js?
// MongoDB is the leading NoSQL database.
// http://en.wikipedia.org/wiki/MongoDB
//
// Run:
// npm install sails-mongo
//
someMongodbServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
// user: 'username',
// password: 'password',
// database: 'your_mongo_db_name_here'
},
If it's not your configuration, it's likely an incompatibility with your version of sails, sails-mongo, or Mongo DB. Which versions of these are you running?

Related

How do I rename a collection with Mongoid 7.x and MongoDB 3.x

I have a test app using Ruby 2.2.2 and am using Mongoid 7.0.0 and Moped 1.5.3 with MongoDB 3.6.2 - we are upgrading an ancient codebase using Mongoid 4.x and MongoDB 2.6 and found numerous breaking-changes in the API along the way
The most serious is we used to be able to do SomeModel.collection.rename however this API method now no longer exists (to my knowledge) and gives an undefined error
I've also tried the following:
Mongoid.default_client.command({ renameCollection: "test.some_collection", to: "test.some_collection2", dropTarget: true })
However this returns
Mongo::Error::OperationFailure: renameCollection may only be run against the admin database. (13)
From a command shell however, I'm able to issue:
db.some_collection.renameCollection("some_collection2")
And this works - this seems to be my only last recourse from what I can see, how would I issue this as a Moped command? (I'm not overly familiar with the syntax scheme)
Also, any reason why such a seemingly straightforward operation is apparently not exposed by Mongoid?
So found a way to do it - some of my collections are stored on different databases
# returns a hash of client config from mongoid.yml eg ["secondary_db", { "database" => "myDB", hosts => [xxx, xxx, xxx] }]
cfg = Mongoid.clients.select { |k,v| Mongoid.clients[k][:database] == MyModel.storage_options[:database] }.first
# now create a new Client instance using the right database
client = Mongo::Client.new(cfg[1]["hosts"], { database: cfg[1]["database"]})
client.command("$eval" => "db.my_collection.renameCollection('new_col_name')")

Mongodb "auth fails" with mongodb php driver and new php library

Using the new mongodb driver: https://github.com/mongodb/mongo-php-driver and the new php library for it: https://github.com/mongodb/mongo-php-library I am getting "auth fails" trying to perform a simple find() query.
In the following code, the connection string follows the pattern mongodb://user:password#mongoinstance:port/database. The connection string works with find() using the old legacy mongo driver, but not the new mongodb driver. The new mongodb is correctly installed in php and displays in phpinfo, the only breaking change we needed to make was to use "new MongoDB\Client" instead of new MongoClient for the legacy mongo driver.
However, when I try to run the following find(), I get auth fails exception in vendor/mongodb/mongodb/src/Operation/Find.php line 179
Using legacy mongo driver there are no problems. Any ideas on the auth fails? What is the mongodb driver failing on exactly? Correct credentials for database and collection are being passed in the mongodb://string. Works in legacy fails with new driver and library.
Environment:
Windows 10
Wamp
PHP 5.5.12
Mongodb driver 1.1.4
Latest version of new php library (Installed with composer: composer require "mongodb/mongodb=^1.0.0")
Mongo instance version 2.4.6
I just had the same error and found out that I had to place the database-name in the connection string.
The documentation here says:
If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.
And the user I'm using has no rights to the admin-database, so this is why I received the authentication error.
I advise you to check this too. You can't provide the database-name the same way as with the MongoClient via the connection options.
So here's the solution. After 3 days of banging my head against a wall it turns out the new mongodb driver parses the mongodb uri differently than the legacy mongo driver. My password had a % sign in it. As soon as I changed the % sign to something else everything worked as expected.

Mongo::Error::OperationFailure (not authorized on [db] to execute command....(13))

On my production server, I keep getting not authorized error randomly. The following is my setup:
MongoDB 3.2.1
Mongo (ruby driver) 2.2.3
Mongoid 5.1.1
bson 4.0.2
I don't have username and password configured in mongoid.yml. I only have uri configured to connect to remote database server.
I search-fu was weak, and couldn't find anything that could explain/help what's going on.
Any help would be much, much appreciated.
Thank you,
It seems like upgrading to mongo 3.x fixes the problem, as this jira ticket shows.
https://jira.mongodb.org/browse/RUBY-1100

Auth Failed trying to connect from a Fantom script to a MongoDB hosted in MongoLab. What's wrong?

I'm trying to connect to a remote MongoDB v3.0.8 hosted in MongoLab using a Fantom v1.0.67 script. The driver I'm using is afMongo v1.0.4. The connection line is:
mongoClient := MongoClient(
ActorPool(),
`mongodb://mydbuser:mydbpassword#ds0#####.mongolab.com:#####/mymongodb`
)
Please note that the placeholders mydbuser, mydbpassword and ##### are replaced with the correct values. The connection is successful when I run the following command from a shell:
mongo ds0#####.mongolab.com:#####/mymongodb -u mydbuser -p mydbpassword
but from the Fantom script, I get this error:
afMongo::MongoCmdErr: Command 'authenticate' failed. MongoDB says: auth failed
afMongo::Operation.runCommand (Operation.fan:36)
afMongo::Operation.runCommand (Operation.fan)
afMongo::Connection$.authenticate (Connection.fan:34)
afMongo::TcpConnection.authenticate (Connection.fan:51)
afMongo::ConnectionManagerPooled.checkOut (ConnectionManagerPooled.fan:458)
afMongo::ConnectionManagerPooled.leaseConnection (ConnectionManagerPooled.fan:320)
afMongo::Cmd.run (Cmd.fan:71)
afMongo::Database.runCmd (Database.fan:36)
afMongo::MongoClient.runAdminCmd (MongoClient.fan:107)
afMongo::MongoClient.buildInfo (MongoClient.fan:64)
afMongo::MongoClient.startup (MongoClient.fan:119)
afMongo::MongoClient.makeFromUri$ (MongoClient.fan:41)
afMongo::MongoClient.makeFromUri$ (MongoClient.fan)
afMongo::MongoClient.makeFromUri (MongoClient.fan:38)
I have also tried Robomongo v0.8.4 with a similar result: A pop-up dialog saying...
Successfully connected to ds0#####.mongolab.com:#####
Authorization failed
I ran the Fantom script as well as Robomongo connecting and authenticating successfully against MongoDB v2.6.3 and v3.0.8 databases hosted locally.
My Java version is Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
I don't know if Robomongo or Fantom/afMongo depend on a Java or System library that is out of date.
What is wrong or what I should be checking, please?
The auth failures in both Robomongo v0.8.4 and afMongo 1.0.4 are due to a new authentication mechanism in MongoDB v3 called SCRAM-SHA-1.
afMongo has been updated with an implementation of SCRAM-SHA-1 over SASL. It auto detects Mongo v3 databases and switches the auth protocol, falling back to the older MONGODB-CR when needed - see this commit.
These changes haven't been released yet because it depends on a new method Buf.pbk(...) that is only available in Fantom 1.0.68 - which itself is unreleased. An updated afMongo v1.0.6 will be released as soon as Fantom 1.0.68 is.
You could compile Fantom 1.0.68 and afMongo 1.0.6 from source, but to be honest, the easiest fix (in the meantime) is to just use a v2.6 MongoDB database.
Note that, if needed, the MongoChef GUI client can authenticate against MongoDB v3 databases.

Mongo vs Mongoid - why can 1 connect and the other not?

I have a rails-app which uses both mongoid and mongo. I use mongoid for my own models, and I use mongo because I have ruote with a ruote-mon storage.
In production however; I get
Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017
when I try to connect to the ruote storage. Even when I just do Mongo::MongoClient.new
Steps I have taken so far to try to resolve this:
I have made my mongodb an explicit master by setting master = true in /etc/mongod.conf
There are no $ENV variables set that could intervene with Mongo::MongoClient.new (double checked)
I have tried to connect using Mongo::MongoClient.new(:slave_ok => true) - same error
I have restarted my mongo database several times (w/o success).
I have checked my firewall settings and I can connect to localhost:27017 with telnet (as said, the mongoid documents can be fetched and stored w/o issue)
I am out of my wits... Any suggestions?
The reason this happened is because we were sending queries with meta operators ($query, $orderby, etc...) for the ismaster command during a connect. This command's output is used to determine whether you are connected to a primary or not and would fail because very old versions of mongodb don't support the use of meta operators.
This fix will be in version 1.8.2 of the gem but I strongly encourage anyone who is still running pre-1.8 versions of mongodb to upgrade. 2.0 is the current legacy release as of the time of this post and even 1.8 is no longer widely supported.
As jmettraux mentioned you can find more details about this on the MongoDB project Jira under Ruby-525
please look at: https://jira.mongodb.org/browse/RUBY-525
Should be fixed by the 1.8.2 mongo gem.