diff --git a/packages/moleculer-db-adapter-mongo/src/index.js b/packages/moleculer-db-adapter-mongo/src/index.js index 962dfe70..98f88159 100644 --- a/packages/moleculer-db-adapter-mongo/src/index.js +++ b/packages/moleculer-db-adapter-mongo/src/index.js @@ -25,7 +25,7 @@ class MongoDbAdapter { */ constructor(uri, opts, dbName) { this.uri = uri, - this.opts = opts; + this.opts = opts || {}; this.dbName = dbName; } @@ -257,7 +257,7 @@ class MongoDbAdapter { entityToObject(entity) { let json = Object.assign({}, entity); if (entity._id) - json._id = this.objectIDToString(entity._id); + json[this.opts.jsonId ? this.opts.jsonId : "_id"] = this.objectIDToString(entity._id); return json; }