私のチャンスの価値を高めることは苦労しています。 なんらかの理由で、それを修正することはありません。私はそれが$inc
の行と関係があると思います。ここでmongooseクエリが変更されることはありません
は私のコードです:
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,
}
}
],
}
],
EDIT:
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 }
EDIT 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