我有对象数组的数据,即
$arrayObj=[{name:'Jack'},{name:'Ram'},{name:'Sham'}];
现在,我需要使用'mycollection'集合名称动态创建集合。之后的收集应该是: -
MyCollection的=> {name:Jack},{name:Ram},{name:Sham}
我知道如何使用Model
插入数据。
答案 0 :(得分:0)
有一个解决方案:
var thingSchema = new Schema({}, { strict: false, collection: 'mycollection' });
//strict, if true then values passed to our model constructor that were not specified in our schema do not get saved to the db.
//collection, for prevent from auto append 's'.
var Thing = mongoose.model('mycollection', thingSchema);
var thing = new Thing($arrayObj);
thing.save();