Я хочу обновить документ по имени поля (riderUserId) с помощью findOneAndUpdate
Вместо обновления документа используется riderUserId
.
updateProfile: function(req, res) {
var riderUserID = req.params.riderUserID;
profileModel.findOneAndUpdate(riderUserID, req.body,
{ overwrite: true, new: true }, (error, response) => {
if (error) {
res.json(error);
console.error(error);
return;
}
res.json(response);
});
},
Это моя модель
var profileSchema = new Schema({
name: { type: String },
surname: { type: String },
gender: { type: String },
email: { type: String },
riderUserId: { type: String },
mobileNumber: { type: Number },
birthYear: { type: Number },
nationality: { type: String },
idNumber: { type: String },
quickDescription: { type: String },
numberPlate: { type: String },
make: { type: Number },
model: { type: String },
memberType: { type: String },
accountHolderName: { type: String },
accountNumber: { type: Number },
nameOfBank: { type: String },
branchCode: { type: Number },
profilePicture: { type: String },
carPicture: { type: String },
music: { type: String },
conversations: { type: String },
pets: { type: String },
smoking: { type: String },
emailVerification: { type: Boolean },
phoneVerification: { type: Boolean },
idVerification: { type: Boolean },
});
А вот два документа,
{
"_id" : ObjectId("5bed37dc84fd420002791e0c"),
"email" : "shoba.hasini@gmail.com",
"riderUserId" : "ZH8irbzGt8WULt2lFSIU5J48Alz2",
"name" : "Shoba",
"surname" : "Hasini",
"gender" : "",
"mobileNumber" : null,
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("5bed37f484fd420002791e0d"),
"email" : "kartikajas@gmail.com",
"riderUserId" : "e1FUpfsDiwSVxcz50ZbhjWKfKGM2",
"name" : "Karthik",
"surname" : "Keyan",
"gender" : "",
"mobileNumber" : null,
"__v" : NumberInt(0)
}
После обновления документа По findOneAndUpdate оба документа становятся одинаковыми
, {
"_id" : ObjectId("5bed37dc84fd420002791e0c"),
"name" : "Karthik",
"surname" : "Keyan",
"gender" : "male",
"email" : "kartikajas@gmail.com",
"riderUserId" : "e1FUpfsDiwSVxcz50ZbhjWKfKGM2",
"mobileNumber" : NumberInt(90087),
"idVerification" : false
}
{
"_id" : ObjectId("5bed37f484fd420002791e0d"),
"email" : "kartikajas@gmail.com",
"riderUserId" : "e1FUpfsDiwSVxcz50ZbhjWKfKGM2",
"name" : "Karthik",
"surname" : "Keyan",
"gender" : "",
"mobileNumber" : null,
"__v" : NumberInt(0)
}
Почему не обновляется один документ с помощью riderId e1FUpfsDiwSVxcz50ZbhjWKfKGM2