Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(map): document key name constraints #14791

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `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