Reputation: 14236
I have data of array of objects i.e,
$arrayObj=[{name:'Jack'},{name:'Ram'},{name:'Sham'}];
Now, i need to create collection dynamically with 'mycollection' collection name. After that collection should like be:-
mycollection=> {name:Jack}, {name:Ram}, {name:Sham}
I know how to insert data by using Model
.
Upvotes: 0
Views: 1609
Reputation: 14236
Got a solution:
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();
Upvotes: 1