我正在努力增加我的机会的价值。 出于某种原因,它不会修改它,我认为它与$inc
内的行有关。猫鼬查询不会被修改
这里是我的代码:
var location: 1,
option = 1,
t = option - 1,
increase = 500;
easyCrime.update({userid: playerid, "locations.location" : location, "locations.location.easycrime.id" : option }, {"$inc" : {"locations.$.location.easycrime[t].chance" : increase}}).then(function (result) {
console.log(result);
});
结果:
{ ok: 1, nModified: 0, n: 0 }
为什么心不是这种修改?
型号:
userid: {
type: String,
default: '57c1c0f3b6b20c011242bf22'
},
locations: [
{
userid: {
type: String,
default: '57c1c0f3b6b20c011242bf22'
},
location: {
type: Number,
default: 1
},
easycrime: [
{
optioname : {
type: String,
default: 'text'
},
chance: {
type: Number,
default: 200
},
id : {
type: Number,
default: 1,
}
}
],
}
],
编辑:
发现,locations.location.easycrime不存在。 更新代码:
easyCrime.update({userid: playerid, "locations.location" : location, "locations.easycrime.id" : option }, {"$inc" : {"locations.$.easycrime[0].chance" : increase}}).then(function (result) {
console.log("inserted chance");
console.log(result);
return resolve(result);
});
,但仍然不会工作{ ok: 0, n: 0, nModified: 0 }
编辑2:
尝试以下查询:
var location: 1,
option = 1,
t = option - 1,
increase = 500;
console.log("updating chance " + increase);
easyCrime.update({userid: playerid, "locations.location" : location, "locations.easycrime.id" : option }, {$inc : {"locations.$.easycrime.$.chance" : increase}}).then(function (result) {
console.log("inserted chance");
console.log(result);
});
但console.log("inserted chance");
和console.log(result);
不会被执行。 (意思是,它不会运行)
模式下,你发现的地点,并在地方你会发现easycrime。那至少是我想要的。 @阿鲁纳,我看到了错误,但不知道它是否会解决它。 – maria
@Aruna,更新线程。 – maria
请看看我的答案,其他建议 – Aruna