以下是我的更新代码:
async.each(jsondata,
function(itemdata, callbackNew){
itemdata.store_code=parseInt(itemdata.store_code);
//console.log(itemdata.store_code);
db.mdb.collection('counters')
.update(
{"store_code": itemdata.store_code},{$set:itemdata},
{ upsert: true },
function (erreach, data) {
if (erreach) {
console.log("error reported")
console.log(erreach)
callbackNew(erreach);
}
else{
//console.log('Data updated')
callbackNew();
app.send(req,res,data);
}
})
},function(err){
if(err) {
//console.log("this is the error"+err)
app.senderr(req,res,err);
}
else{
app.send(req,res,jsondata);
}
});
但是DB没有被更改。更新前后的值相同。 下面是我的数据库的JSON。
{
"_id" : ObjectId("586aac4c8231ee0b98458045"),
"store_code" : NumberInt(10800),
"counter_name" : "R.N.Electric",
"address" : "314 khatipura road",
"locality" : "Khatipura Road (Jhotwara)",
"pincode" : "302012",
"town" : "JAIPUR",
"gtm_city" : "JAIPUR",
"sales_office" : "URAJ",
"owner_name" : "Rajeev",
"owner_mobile" : "9828024073",
"division_mapping" : [
{
"dvcode" : "cfc",
"dc" : "trade",
"beatcode" : "govindpura",
"fos" : {
"_id" : ObjectId("586ab8318231ee0b98458843"),
"loginid" : "9928483483",
"name" : "Arpit Gupta",
"division" : [
"cfc",
"iron"
],
"sales_office" : "URAJ",
"gtm_city" : "JAIPUR"
},
"beat" : {
"_id" : ObjectId("586d372b39f64316b9c3cbd7"),
"division" : {
"_id" : ObjectId("5869f8b639f6430fe4edee2a"),
"clientdvcode" : NumberInt(40),
"code" : "cfc",
"name" : "Cooking & Fabric Care",
"project_code" : "usha-fos",
"client_code" : "usha",
"agent_code" : "v5global"
},
"beatcode" : "govindpura",
"sales_office" : "URAJ",
"gtm_city" : "JAIPUR",
"active" : true,
"agency_code" : "v5global",
"client_code" : "USHA_FOS",
"proj_code" : "usha-fos",
"fos" : {
"_id" : ObjectId("586ab8318231ee0b98458843"),
"loginid" : "9928483483",
"name" : "Arpit Gupta",
"division" : [
"cfc",
"iron"
],
"sales_office" : "URAJ",
"gtm_city" : "JAIPUR"
}
}
}
],
"distributor_mail" : "sunil.todi@yahoo.in",
"project_code" : "usha-fos",
"client_code" : "usha",
"agent_code" : "v5global",
"distributor_name" : "Sundeep Electrical"
}
以下是我发送的更新文件($ set:itemdata):
{ store_code: '10800',
counter_name: 'R.N.Electrics',
address: '314 khatipura road',
locality: 'Khatipura Road (Jhotwara)',
pincode: '302012',
town: 'JAIPUR',
gtm_city: 'JAIPUR',
sales_office: 'URAJ',
owner_name: 'Rajeev',
owner_mobile: '9828024073',
distributor_mail: 'sunil.todi@yahoo.in',
distributor_name: 'Sundeep Electrical' }