2014-06-09 4 views
6

Dans mon schéma, si je options à metrics : [ { options : {} } ] puis-je obtenir:étrange Mongoose erreur de - `options` ne peut pas être utilisé comme un chemin de schéma

/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 

Mais si le changement options à tout autre mot ... comme qoptions .... alors l'erreur disparaît. Pourquoi cela arrive-t-il?

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; 

Répondre

20

Mongoose a un certain nombre de noms de schéma Reserved qui ne peuvent pas être utilisés, pour éviter tout conflit avec la mise en œuvre interne de mangouste. La liste, de la docs donne ce qui suit comme réservé:

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

Ces termes doivent être évités dans votre schéma!

Questions connexes