0

I have two docker containers, one for the database and another one for the API. I am trying to do some test in API and I need to use monckgoose. I can create a succesfully connection with mongoose, but I get MongoError: Authentication failed. when I try to create the connection through mockgoose.

mockgoose.prepareStorage().then(() => {
    console.log("inside prepareStorage");
    mongoose.Promise = promise;
    console.log("before connect);
    mongoose.connect(url, options, (error) => {
        console.log("error:" + error);
    });
}).catch((error) => {
    console.log(error);
});

url is --> mongodb://database/myDB where database is the of the service inside the docker-compose.yml options param only contains user and pass that are correct.

The database logs shows the following information:

2018-03-08T17:22:44.549+0000 I COMMAND  [conn2] command admin.$cmd command: isMaster { ismaster: true, $readPreference: { mode: "secondaryPreferred" }, $db: "admin" } numYields:0 reslen:223 locks:{} protocol:op_query 137ms
2018-03-08T17:26:14.033+0000 I COMMAND  [thread4] command config.$cmd command: createIndexes { createIndexes: "system.sessions", indexes: [ { key: { lastUse: 1 }, name: "lsidTTLIndex", expireAfterSeconds: 1800 } ], $db: "config" } numYields:0 reslen:134 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 } } } protocol:op_msg 207ms

Does anyone know why I can not create the connection within prepareStorage?

Diego
  • 304
  • 1
  • 8
  • Do the mongo DB logs say anything? – six8 Jan 24 '18 at 19:57
  • @six8 I have updated the thread with db logs. Thank you! – Diego Mar 08 '18 at 17:36
  • I don't know why mockgoose is doing operations on config and admin databases where I am stablishing the connection in another database – Diego Mar 08 '18 at 17:38
  • I don't see any login attempts within the log. Sorry, I don't know enough about mockgoose to provide any further help. – six8 Mar 13 '18 at 17:14
  • Don't worry @six8 i have found another mocking library and it is working very well. https://github.com/alonronin/mockingoose – Diego Mar 14 '18 at 18:42

0 Answers0