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?