通过mongoose在mongoDB中创build无模式的收集

我有以下mongoose模式logging:

var mongoose = require('mongoose'); module.exports = mongoose.model('lM', { any : mongoose.Schema.Types.Mixed, },'mlr'); 

在我的代码中,我正在这样做:

 var lm = require('../server/models/records'); new lm().save(lmr); 

作为lmr是一个JSON对象。

这产生了一个我提供的名字的mongodb数据库,但是这个集合里的logging只包含:

 _id: objectID _v: 0 

JSON对象无处可见。 我怎样才能得到架构中的任何包装的JSON对象?

 var lm = require('../server/models/records'); new lm({'any':lmr}).save(); 

在save()方法中传递callback函数[可选],如果你想追踪错误,如果有的话。

 new lm({'any':lmr}).save(function(err){ if(err) { console.log(err) }else{ console.log('saved') } }); 

要创build无模式集合,您必须设置strict:false ,默认为true。 严格选项确保传递给您的模型构造函数的未在模式中指定的值不保存到数据库。

严格的选项文件

Interesting Posts