From 796f9d7565a1961edf6a773a262699043804f949 Mon Sep 17 00:00:00 2001 From: "John H. Kohler" Date: Mon, 15 Feb 2021 10:52:05 -0500 Subject: [PATCH 1/2] add object id.toString() on methods --- lib/types/map.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/types/map.js b/lib/types/map.js index b992259870b..f22daca760d 100644 --- a/lib/types/map.js +++ b/lib/types/map.js @@ -1,6 +1,7 @@ 'use strict'; const Mixed = require('../schema/mixed'); +const ObjectId = require('./objectid') const deepEqual = require('../utils').deepEqual; const get = require('../helpers/get'); const handleSpreadDoc = require('../helpers/document/handleSpreadDoc'); @@ -41,6 +42,10 @@ class MongooseMap extends Map { } get(key, options) { + if(key instanceof ObjectId) { + key = key.toString(); + } + options = options || {}; if (options.getters === false) { return super.get(key); @@ -49,6 +54,10 @@ class MongooseMap extends Map { } set(key, value) { + if(key instanceof ObjectId) { + key = key.toString(); + } + checkValidKey(key); value = handleSpreadDoc(value); @@ -107,6 +116,10 @@ class MongooseMap extends Map { } delete(key) { + if(key instanceof ObjectId) { + key = key.toString(); + } + this.set(key, undefined); super.delete(key); } From 8d0311eef495c60385e9f2fc17a81eb8b996e4f8 Mon Sep 17 00:00:00 2001 From: "John H. Kohler" Date: Mon, 15 Feb 2021 11:17:44 -0500 Subject: [PATCH 2/2] fix linting errors --- lib/types/map.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/types/map.js b/lib/types/map.js index f22daca760d..8d67324ea29 100644 --- a/lib/types/map.js +++ b/lib/types/map.js @@ -1,7 +1,7 @@ 'use strict'; const Mixed = require('../schema/mixed'); -const ObjectId = require('./objectid') +const ObjectId = require('./objectid'); const deepEqual = require('../utils').deepEqual; const get = require('../helpers/get'); const handleSpreadDoc = require('../helpers/document/handleSpreadDoc'); @@ -42,7 +42,7 @@ class MongooseMap extends Map { } get(key, options) { - if(key instanceof ObjectId) { + if (key instanceof ObjectId) { key = key.toString(); } @@ -54,8 +54,8 @@ class MongooseMap extends Map { } set(key, value) { - if(key instanceof ObjectId) { - key = key.toString(); + if (key instanceof ObjectId) { + key = key.toString(); } checkValidKey(key); @@ -116,7 +116,7 @@ class MongooseMap extends Map { } delete(key) { - if(key instanceof ObjectId) { + if (key instanceof ObjectId) { key = key.toString(); }