* Since maps are stored as objects under the hood, keys must be strings * and can't contain any invalid characters * @param {string} key * @api private
(key)
| 350 | */ |
| 351 | |
| 352 | function checkValidKey(key) { |
| 353 | const keyType = typeof key; |
| 354 | if (keyType !== 'string') { |
| 355 | throw new TypeError(`Mongoose maps only support string keys, got ${keyType}`); |
| 356 | } |
| 357 | if (key.startsWith('$')) { |
| 358 | throw new Error(`Mongoose maps do not support keys that start with "$", got "${key}"`); |
| 359 | } |
| 360 | if (key.includes('.')) { |
| 361 | throw new Error(`Mongoose maps do not support keys that contain ".", got "${key}"`); |
| 362 | } |
| 363 | if (specialProperties.has(key)) { |
| 364 | throw new Error(`Mongoose maps do not support reserved key name "${key}"`); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | module.exports = MongooseMap; |