MongoError: Ungültige Operation, Keine Operationen in der Masse
Ich bin nicht in der Lage zu tun, bulk insert für den mongo mit Mungo.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//Define our results schema
var webSchema = new Schema({"abc" : String},{
collection: 'web_v2'
});
MyApi.prototype.Webs= mongoose.model('Webs', webSchema);
resultData = [{"abc": "12121221"},{"abc": "44545"},{"abc": "545"}]
MyApi.prototype.Webs.collection.insert(resultData, function (err, myDocuments) {
if (err) {
console.log(err);
} else {
console.log("web inserted : " + myDocuments.result.n);
}
});
Ich bin immer der folgende Fehler
MongoError: Invalid Operation, No operations in bulk
at Function.MongoError.create (/pathtoapp/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
at toError (/pathtoapp/node_modules/mongoose/node_modules/mongodb/lib/utils.js:114:22)
at OrderedBulkOperation.execute (/pathtoapp/node_modules/mongoose/node_modules/mongodb/lib/bulk/ordered.js:500:11)
at bulkWrite (/pathtoapp/node_modules/mongoose/node_modules/mongodb/lib/collection.js:582:8)
at Collection.insertMany (/pathtoapp/node_modules/mongoose/node_modules/mongodb/lib/collection.js:477:44)
at Collection.insert (/pathtoapp/node_modules/mongoose/node_modules/mongodb/lib/collection.js:753:15)
at NativeCollection.(anonymous function) as insert (/pathtoapp/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:136:28)
at /pathtoapp/index.js:481:57
at /pathtoapp/node_modules/async/lib/async.js:721:13
at /pathtoapp/node_modules/async/lib/async.js:52:16
at async.forEachOf.async.eachOf (/pathtoapp/node_modules/async/lib/async.js:236:30)
at _parallel (/pathtoapp/node_modules/async/lib/async.js:712:9)
at Object.async.parallel (/pathtoapp/node_modules/async/lib/async.js:726:9)
at /pathtoapp/index.js:479:43
at /pathtoapp/node_modules/async/lib/async.js:721:13
at /pathtoapp/node_modules/async/lib/async.js:52:16
jemand bitte lassen Sie mich wissen, was mache ich falsch.?
- wer die Verkleidung gleichen problem..?
- dasselbe problem erlebe ich jetzt alle updates????
Web.collection.insert
ist Mongo syntax, nicht Mungo. Ich bin mir nicht sicher, warum es ausfällt. Da bist du aber mit Mungo, die Sie verwenden könnenWebs.insertMany(resultData)
. docs hier
Du musst angemeldet sein, um einen Kommentar abzugeben.
Höchstwahrscheinlich werden Sie versuchen, legen Sie eine leere array.
Hier ist die MongoDB Jira-Website auf, um diesen Fehler
Nur prüfen, ob die bulk-Instanz-Operationen vor dem Aufruf
execute
mit dieser Funktion:Hier ist mein check-in eine einfache if-block an, wenn Sie mit der raw-MongoDB-Treiber für Node js, es könnte helfen: