Solved: if anybody is interested, it seems that MongoDB is just starting automatically on Windows startup...
I have this function to initialize a Mongoose connection:
const mongoose = require('mongoose');
let db;
async function initDD(){
try {
db = await mongoose.connect('mongodb://localhost:27017/local', { useNewUrlParser: true });
} catch (error) {
console.log('mongoose error',error)//Doesn't come to this...
}
}
This promise doesn't get rejected, even if i haven't started my MongoDB service yet. I tried also the callback version- same result. I clearly do not have any MongoDB running, and yet Mongoose connects as if nothing is wrong.
What could be the problem here? I have a standard MongoDB setup, latest Mongoose, Windows 7 and Node 10.
Edit: the logged value of the db, when no MogoDB is running:
Mongoose {
connections:
[ NativeConnection {
base: [Circular],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object],
_readyState: 1,
_closeCalled: false,
_hasOpened: true,
plugins: [],
_listening: false,
_connectionOptions: [Object],
name: 'local',
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
client: [MongoClient],
'$initialConnection': [Promise],
db: [Db] } ],
models: { User: Model { User } },
modelSchemas:
{ User:
Schema {
obj: [Object],
paths: [Object],
aliases: {},
subpaths: {},
virtuals: [Object],
singleNestedPaths: {},
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
methodOptions: {},
statics: {},
tree: [Object],
query: {},
childSchemas: [],
plugins: [Array],
'$id': 1,
s: [Object],
_userProvidedOptions: {},
options: [Object],
'$globalPluginsApplied': true } },
options: { pluralization: true, [Symbol(mongoose:default)]: true },
_pluralize: [Function: pluralize],
Schema:
{ [Function: Schema]
reserved:
[Object: null prototype] {
populated: 1,
remove: 1,
validate: 1,
toObject: 1,
schema: 1,
save: 1,
modelName: 1,
get: 1,
isNew: 1,
isModified: 1,
init: 1,
errors: 1,
db: 1,
collection: 1,
removeListener: 1,
listeners: 1,
once: 1,
on: 1,
emit: 1,
prototype: 1 },
Types:
{ String: [Function],
Number: [Function],
Boolean: [Function],
DocumentArray: [Function],
Embedded: [Function: SingleNestedPath],
Array: [Function],
Buffer: [Function],
Date: [Function],
ObjectId: [Function],
Mixed: [Function],
Decimal: [Function],
Decimal128: [Function],
Map: [Function: Map],
Oid: [Function],
Object: [Function],
Bool: [Function],
ObjectID: [Function] },
ObjectId:
{ [Function: ObjectId]
schemaName: 'ObjectId',
get: [Function],
_checkRequired: [Function],
_cast: [Function: castObjectId],
cast: [Function: cast],
checkRequired: [Function] } },
model: [Function],
plugins:
[ [ [Function], [Object] ],
[ [Function], [Object] ],
[ [Function], [Object] ],
[ [Function], [Object] ] ] }