Map


MongooseMap.prototype.$isMongooseMap

Type:
  • «property»

Set to true for all Mongoose map instances


MongooseMap.prototype.clear()

Overwrites native Map's clear() function to support change tracking.


MongooseMap.prototype.delete()

Overwrites native Map's delete() function to support change tracking.


MongooseMap.prototype.get()

Overwrites native Map's get() function to support Mongoose getters.


MongooseMap.prototype.set()

Overwrites native Map's set() function to support setters, populate(), and change tracking. Note that Mongoose maps only support strings and ObjectIds as keys.

Example:

doc.myMap.set('test', 42); // works
doc.myMap.set({ obj: 42 }, 42); // Throws "Mongoose maps only support string keys"

MongooseMap.prototype.toBSON()

Converts this map to a native JavaScript Map so the MongoDB driver can serialize it.


MongooseMap.prototype.toJSON()

Parameters:
  • [options] «Object»
    • [options.flattenMaps=false] «Boolean» set to true to convert the map to a POJO rather than a native JavaScript map

Converts this map to a native JavaScript Map for JSON.stringify(). Set the flattenMaps option to convert this map to a POJO instead.

Example:

doc.myMap.toJSON() instanceof Map; // true
doc.myMap.toJSON({ flattenMaps: true }) instanceof Map; // false