diff --git a/lib/types/map.js b/lib/types/map.js index b992259870b..8d67324ea29 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); }