Ho bisogno di aiuto con questo. Ho questo progetto di nodo che ha funzionato dall'inizio. Recentemente ho iniziato ad avere un errore su mangusta non essere in grado di aggiornare __v un __v allo stesso tempo (dettagli di seguito) Il mio primo pensiero è stato che un nuovo aggiornamento di mangusta ha provocato questo, ma non ne sono sicuro. Qualsiasi aiuto sarà apprezzato. GrazieErrore di modifica: Impossibile aggiornare __v e __v allo stesso tempo
/.../node_modules/mongoose/lib/utils.js:413
throw err;
^
MongoError: exception: Cannot update '__v' and '__v' at the same time
at Object.toError (/.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)
at /.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1131:31
at /.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1846:9
at Server.Base._callHandler (/.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:445:41)
at /.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:478:18
at MongoReply.parseBody (/.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:436:20)
at EventEmitter.emit (events.js:95:17)
at null.<anonymous> (/.../node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
at EventEmitter.emit (events.js:98:17)
EDIT si presenta come l'errore viene generato quando tento di salvare. Ecco il metodo di salvataggio che chiamo;
save: function (callback) {
// A Helper function
function setID(instance, id) {
instance._id = id;
};
var self = this; // Preserve reference to the instance
var update = Utils.clone(this);
delete update._id; // Delete the _id property, otherwise Mongo will return a "Mod on _id not allowed" error
// Prepare updates for saving
for (var key in update) {
if (update[key] == undefined)
delete update[key];
if (key == 'company' || key == 'local_currency')
update[key] = update[key].getID();
}
PreferenceModel.save(this._id, update, function (err, savedDoc) {
if (err) callback(err);
else {
if (!self.getID()) // If the object didn't previously have an _id property
setID(self, savedDoc._id);
callback(null, self);
}
});
}
ed ecco dove lo chiamo;
preference.save(function (err, savedPreference) {
if (err) callback(err);
else callback(null);
});
inoltre, ecco il metodo PreferenceModel.save;
function save(id, update, callback) {
Preference.findByIdAndUpdate(id, update, {upsert: true}, function (err, savedDoc) {
if (err) callback(err);
else callback(null, savedDoc);
});
}
È possibile modificare la domanda per includere il codice che causa l'errore? – JohnnyHK
Sì, avremo bisogno di vedere un po 'di codice qui. –
Ok, ho aggiunto il codice – user3863128