Home > database >  Mongo update data problem
Mongo update data problem

Time:09-17

Mongo version is 3.0.2, application is nodejs, recently found a lost updates mongo,
Nodejs request log detected the missing data, return to the state of the is 200, but in mongo library,

Mongo in two patches on a chip did replicate sets, a poll two data node,
Less than 1000, the current library ops update accounts for most,

Nodejs:
 
Var query={
DeviceId: deviceId,
Date: my moment (playDate. The format (" YYYY - MM - DD ")),
AdId: logItemInstance adId,
OrderId: logItemInstance orderId,
Is_cross_day: isCrossDay
};
Var update={
$set: {lut: my moment (), appVersion: appVersion, agentId: agentId},
$inc: {count: 1},
$push: {
Detail: {
PT: my moment (),
DPT: logItemInstance. PlayTime,
RecordId: value. Id,
}
}
};

AdPlayRecordNewModel. Update (query, update, {upsert: true}, function (err, a) {
If (err) {
Next (err);
} else {
SubNext (null, subValue);
}
});


Mongo model:
 
Var safe={w: 1, j: true, wtimeout: 60 * 1000};
Var mongoose=the require (" mongoose ");
Var modelName="adPlayRecordNewModel";
Var dbName="ad_play_records_new";
Var modelSchema=new mongoose. Schema ({
Date: the date,
DeviceId: String,
AgentId: Number,
AdId: Number,
OrderId: Number,
Count: Number,
AppVersion: String,
Lut: Date,
Is_cross_day: {type: Boolean, default: false},
Detail: [{
PT: Date,
DPT: Date,
RecordId: Number
}]
}, safe);

Var instanse=mongoose. Model (modelName modelSchema, dbName);
The module. Exports=instanse;

CodePudding user response:

Check the opslog whether there is the update statement

CodePudding user response:

The oplog turned over and don't have the figures, ready to try the w: 1 to w: 2, in the observation, the official document 2.6 to solve the problem of writing lost,

CodePudding user response:

Upgrade to the latest version of the 3 small before 3.0 version does have submit bug do not check the data

CodePudding user response:

A serious lost data, mogodb determined to give up

CodePudding user response:

Reference:
https://docs.mongodb.com/manual/reference/write-concern/

W: & lt; Number>
Any data - bearing member of the up set can contribute to the write acknowledgment of w: & lt; Number> The write operations.
The following table lists The when The member can acknowledge The write -based on The j value:

J is unspecified
Acknowledgment the requires their operation in the memory (j: false).
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If you don't have any special Settings, so the j: false, that means you are written to the memory only, so even if write success, also does not guarantee that is not lost

CodePudding user response:

And also because the default is written to memory is succeed, so the oplog also couldn't find it

CodePudding user response:

W: 2 to ensure that there are two copy write, as long as you don't down at the same time, won't appear the problem of lost data
If you want to completely ensure not losing data, should be confirmed to disk, namely j: true
  • Related