mongoose save vs insert vs create
Was sind verschiedene Möglichkeiten, ein Dokument (Datensatz) mit Mongoose in MongoDB einzufügen?
Mein aktueller Versuch:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var notificationsSchema = mongoose.Schema({
"datetime" : {
type: Date,
default: Date.now
},
"ownerId":{
type:String
},
"customerId" : {
type:String
},
"title" : {
type:String
},
"message" : {
type:String
}
});
var notifications = module.exports = mongoose.model('notifications', notificationsSchema);
module.exports.saveNotification = function(notificationObj, callback){
//notifications.insert(notificationObj); won't work
//notifications.save(notificationObj); won't work
notifications.create(notificationObj); //work but created duplicated document
}
Eine Idee, warum Einfügen und Speichern in meinem Fall nicht funktioniert? Ich habe versucht zu erstellen, es hat 2 Dokumente anstelle von 1 eingefügt. Das ist seltsam.