2014-06-09 11 views
6

Nel mio schema, se ho options in metrics : [ { options : {} } ] allora ottengo:Strano Mongoose schema.js errore - `options` non può essere utilizzato come un percorso schema

/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 

Ma se il cambiamento options a qualsiasi altra parola ... come qoptions .... quindi l'errore scompare. Perché sta succedendo?

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; 

risposta

20

Mongoose ha un certo numero di Reserved nomi di schema che non possono essere utilizzati, per evitare conflitti con implementazione interna di Mongoose. L'elenco, dal docs dà la seguente come riservati:

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

Questi termini dovrebbero essere evitati nello schema!

Problemi correlati