I tried to much posibilities that I found searching for this error without success.
I can connect to my mongo with the CLI typing mongo --port myPort -u myUser ...
But I need to connect my app (in the same host) by URI.
This is what I get:
mongo mongodb://username:password#localhost:myPort/myDb
MongoDB shell version: 2.6.10
connecting to: mongodb://username:password#localhost:myPort/myDb
2017-05-19T23:34:33.568+0200 Assertion failure _setName.size() src/mongo/client/dbclientinterface.h 231
2017-05-19T23:34:33.569+0200 0x6b75c9 0x659e9f 0x636a32 0x5013b8 0x4fa7f1 0x6006fd 0x5eb869 0x7fdcdff35d76 0x1ebf47506362
mongo(_ZN5mongo15printStackTraceERSo+0x39) [0x6b75c9]
mongo(_ZN5mongo10logContextEPKc+0x21f) [0x659e9f]
mongo(_ZN5mongo12verifyFailedEPKcS1_j+0x142) [0x636a32]
mongo(_ZN5mongo16ConnectionStringC1ENS0_14ConnectionTypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_+0x208) [0x5013b8]
mongo(_ZN5mongo16ConnectionString5parseERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x201) [0x4fa7f1]
mongo(_ZN5mongo17mongoConsExternalEPNS_7V8ScopeERKN2v89ArgumentsE+0x11d) [0x6006fd]
mongo(_ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE+0xa9) [0x5eb869]
/usr/lib/libv8.so.3.14.5(+0x99d76) [0x7fdcdff35d76]
[0x1ebf47506362]
2017-05-19T23:34:33.570+0200 Error: assertion src/mongo/client/dbclientinterface.h:231 at src/mongo/shell/mongo.js:148
exception: connect failed
Any idea? :\ Thanks
Solved upgrading mongod from 2.6 to 3.0.15
If you don't want to upgrade to a newer version of MongoDB you can also just drop the mongodb:// from the beginning. For example change:
mongo mongodb://username:password#localhost:myPort/myDb
to:
mongo username:password#localhost:myPort/myDb
Ref: https://jira.mongodb.org/browse/SERVER-15739?focusedCommentId=1000536&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1000536
Related
The error I'm getting is like the following:
Some information that you should know:
I'm using Symfony 5
I'm able to connect to mongo db using MongoDB Compass and in terminal using mongo command
What packages I have installed are the following:
"mongodb/mongodb": "^1.6"
"monolog/monolog": "^2.0"
"symfony/monolog-bundle": "^3.5"
My configuration file monolog.yaml (config/packages/dev/monolog.yaml) is like the following:
monolog:
handlers:
mongo:
type: mongo
mongo:
host: localhost
Thank you.
I had installed mongodb with brew. And I figured out MongoDB\Client class was not recognized. Then I found that we can install mongo driver manually.
I followed the steps here : https://www.php.net/manual/en/mongodb.installation.manual.php
I've changed my monolog configuration file monolog.yaml as
monolog:
handlers:
mongodb:
type: mongo
mongo:
id: mongolog
I added MongoDB\Client as service into service configuration file services.yaml
services:
...
mongolog:
class: MongoDB\Client
And after doing things above, it's worked.
I have been trying for a few days to connect my mongoDB to MEAN stack without success. Its running on AWS lightsail (Bitnami). The website itself is running fine, except for any pages that have an ajax/db call, as the database is not connecting/authenticating my connection string.
I am using the mongo,node, express part of the stack, I do not need or know any angular at present. I thought this would be easier than setting up on nodeJS and then adding mongoDB separately (well i did try that first with similar problems), I do intend to learn angualar in future so this is probably better long term. Server side set up is currently a weakness.
I am using mongoose for the connection. I can access the database using:
mongo admin --username root -p password via SSH.
I can also access the db via Rockmongo SSH. There is currently only one admin user in the database at present i.e. root.
My initial server/startup file is below:
server.js
const app = require('/opt/bitnami/apps/MYAPP/app.js');
require('dotenv').config({ path: 'variables.env' });
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect(process.env.DATABASE_CONN);
app.listen(3000,function(){
console.log("Server has started!");
});
variables.env
DATABASE_CONN = mongodb://root:password#127.0.0.1:27017/MYAPPDATABASE
I have also tried many other connections strings, exchanging root for bitnami default user, etc.
When I go to my app folder and start the server (npm start or node server.js), the website starts up but with the below mongoDB authentication errors, below is only the first section.
> Server has started!
Connection error: { MongoError: Authentication failed.
at /opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/mongodb-core/lib/con
nection/pool.js:595:61
at authenticateStragglers (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modu
les/mongodb-core/lib/connection/pool.js:513:16)
at Connection.messageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_m
odules/mongodb-core/lib/connection/pool.js:549:5)
at emitMessageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
mongodb-core/lib/connection/connection.js:309:10)
at Socket.<anonymous> (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
mongodb-core/lib/connection/connection.js:452:17)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
errmsg: 'Authentication failed.',
code: 18,
codeName: 'AuthenticationFailed' }
Any help or direction would be much appreciated. Thank you kindly.
Mos.
OK. Solution found.
In the mongo.conf file I set the dbpath to /data/db
The mongo shell is pointed to /opt/bitnami/mongodb/tmp/mongodb-27017.sock "$#"
go to /opt/bitnami/mongodb/bin/mongo
change /opt/bitnami/mongodb/tmp/mongodb-27017.sock "$#" to /tmp/mongodb-27017.sock "$#"
Can do that using sudo nano /opt/bitnami/mongodb/bin/mongo then edit the file.
Still have noauth turned on, so next step is getting my db connection string to authenticate.
Hope it helps someone.
Thanks
Some improvement. I have edited mongo.conf for now to enable no auth. I then ran mongod which stated no /data/db folder for which it stores data. So I created the folders and ran mongod again. Now all pages work but the mongo shell command 'mongo' will not work on the terminal.
I think its because the mongod dbpath is set to data/db and the mongodb conf file dbpath is set to /opt/bitnami/mongodb/data/db.
So I am trying to update the mongod dbpath but it doesnt seem to update.
I'm getting this error when trying to login to MongoLab database via command line in Ubuntu
> 2015-07-02T13:44:05.682-0400 I NETWORK DBClientCursor::init call() failed
>2015-07-02T13:44:05.694-0400 E QUERY Error: error doing query: failed
at DBQuery._exec (src/mongo/shell/query.js:83:36)
at DBQuery.hasNext (src/mongo/shell/query.js:240:10)
at DBCollection.findOne (src/mongo/shell/collection.js:187:19)
at DB.runCommand (src/mongo/shell/db.js:58:41)
at DB.isMaster (src/mongo/shell/db.js:680:51)
at DB._getDefaultAuthenticationMechanism (src/mongo/shell/db.js:1227:27)
at DB._authOrThrow (src/mongo/shell/db.js:1252:33)
at (auth):6:8
at (auth):7:2 at src/mongo/shell/query.js:83
exception: login failed
Double-check that your client supports the version of MongoDB your server is running. If you're using one of our experimental databases, they were recently upgraded to MongoDB version 3.0 an its new SCRAM-SHA-1 authentication mechanism. Connecting to these databases now requires the 3.0 Mongo shell or a driver that supports SCRAM-SHA-1.
http://docs.mongodb.org/manual/release-notes/3.0-scram/#upgrade-drivers
If you have any questions, feel free to contact us at support#mongolab.com and we'd be happy to help.
Regards,
Jared
I am new to mongodb, I am able to get my nodejs appserver started with mongodb 2.4 and 2.6. I have a requirement to test the latest mongodb, which is 2.8 with our app. I am able to start the mongodb 2.8 but when I try to start my nodejs appserver, I get following error.
2015-01-16T18:43:51.115Z <warn> globals.js:45 () MONGO URI = mongodb://myuser:password#localhost:27017/test
2015-01-16T18:43:51.178Z <error> globals.js:45 () #### Error in connecting to mongodb
2015-01-16T18:43:51.180Z <error> globals.js:45 () { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
2015-01-16T18:43:51.182Z <error> globals.js:45 () MongoError: auth failed
.........
Also, I have created myuser in the test db and authenticated it successfully. Please help, I have tried all possible ways and with no success. Thank you very much in advance. (my environment is Ubantu Linux 14.04, virtualbox) One more thing that I forgot to mention is that I am using wiredTiger storageEngine. I tried with MMAPv1 as well and same result.
I had the same issue. It worked for me on Mac, but on Linux I hit this failure until I upgraded module mongoose from 3.6.x to 3.8.x (3.8.25). That solved the problem for me. You might consider doing the same, at least to rule out this problem.
i try to add new member to replicas set in mongodb. there is possibility to
do it with os.system. But how would it be with subprocess.call()?
So far i have:
import subprocess
task='''"rs.add('alehandro-VirtualBox:27067')"'''
port=27072
subprocess.call(["/usr/bin/mongo", " --port {0}".format(port), " --eval {0}".format(task)])
OUTPUT:
MongoDB shell version: 2.4.5
connecting to: --port 27072
Sun Jul 28 16:34:18.884 JavaScript execution failed: Error: [ --port 27072] is not a valid database name at src/mongo/shell/mongo.js:L40
exception: connect failed
Can anybody help me with it?
The mongo process is being invoked with a parameter called --port 27072 and a value of --eval .. because of the way you are passing your parameters to subprocess.call.
If you change the subprocess.call invocation to the following, then it should work :
subprocess.call(["/usr/bin/mongo", "--port", str(port), "--eval", task])