Strange Mongoose schema.js error - `options` cannot be used as a schema name

In my scheme, if I have options in metrics : [ { options : {} } ] , I get:

 /home/one/cloudimageshare-monitoring/project/node_modules/mongoose/lib/schema.js:282 throw new Error("`" + path + "` may not be used as a schema pathname"); ^ Error: `options` may not be used as a schema pathname 

But if you change options to any other word ... for example qoptions .... then the error disappears. Why is this happening?

 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var FilesystemSchema = new mongoose.Schema({ timeStamp : { type : Date, index: true }, avaiable : Boolean, status : String, metrics : [ { options : { data : String, type : String, unit : String } }, { freeFiles : { data : Number, type : String, unit : String } }, { total : { data : Number, type : String, unit : String } }, { avail : { data : Number, type : String, unit : String } }, { free : { data : Number, type : String, unit : String } }, { files : { data : Number, type : String, unit : String } }, { used : { data : Number, type : String, unit : String } } ] }); module.exports = FilesystemSchema; 
+6
source share
1 answer

Mongoose has several Reserved schema names that cannot be used to avoid conflicts with the Mongoose internal implementation. The list from docs provides the following values:

 on, emit, _events, db, get, set, init, isNew, errors, schema, options, modelName, collection, _pres, _posts, toObject 

These terms should be avoided in your design!

+20
source

Source: https://habr.com/ru/post/970592/


All Articles