From 7796bfcdfee4f9f7791226aecd3f16635dfcce92 Mon Sep 17 00:00:00 2001 From: Derek Liang Date: Wed, 22 Apr 2020 21:51:11 -0700 Subject: [PATCH] add id alias for json object to override default _id --- packages/moleculer-db-adapter-mongo/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; }