Skip to content

Commit

Permalink
style(map): document key name constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Aug 3, 2024
1 parent 986f5eb commit aa39c68
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/types/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ class MongooseMap extends Map {
* and change tracking. Note that Mongoose maps _only_ support strings and
* ObjectIds as keys.
*
* Keys also cannot:
* - be named after special properties (like `prototype`, `constructor` and `__proto__`)
* - start with a dollar sign (`$`)
* - contain any dots (`.`)
*
* #### Example:
*
* doc.myMap.set('test', 42); // works
* doc.myMap.set({ obj: 42 }, 42); // Throws "Mongoose maps only support string keys"
* doc.myMap.set(10, 42); // Throws "Mongoose maps only support string keys"
* doc.myMap.set("$test", 42); // Throws "Mongoose maps do not support keys that start with "$", got "$test""
*
* @api public
* @method set
Expand Down

0 comments on commit aa39c68

Please sign in to comment.