"Name" : "nameof person",
"_id" : ObjectId("54461c480d9f041a21b4 bba9"),
"items" : ["_id" : ObjectId("54461c480d9f041a21b4
{
"name" : "Item1",
"count" : 1
},
{
"count" : 1
},
{
"name" : "Item2",
"count" : 2
},
{
"name" : "Item3","count" : 2
},
{
"count" : 1
}
],
"Town" : 29,
"Date_Time" : 20141109114512
}
{
"Name" : "nameof person",
"_id" : ObjectId("54461c480d9f041a21b4 13460"),
"items" : ["_id" : ObjectId("54461c480d9f041a21b4
{
}
"name" : "Item1",
"count" : 2
}
Incrementing the 1st record ........Nothing happens, it does not increment the count of Item1 to 2
db.item_table.update({"_id" : ObjectId("54461c480d9f041a21b4 bba9"), 'items.name': 'Item1','Name':"name of person"}, {'$inc': {'items.$.count': 1}})
but for the second record which contains only Item1, it increments the count to 3
db.item_table.update({"_id" : ObjectId("54461c480d9f041a21b4 13460"), 'items.name': 'Item1','Name':"name of person"}, {'$inc': {'items.$.count': 1}})
{
{
}
"count" : 2
}
Incrementing the 1st record ........Nothing happens, it does not increment the count of Item1 to 2
db.item_table.update({"_id" : ObjectId("54461c480d9f041a21b4
but for the second record which contains only Item1, it increments the count to 3
db.item_table.update({"_id" : ObjectId("54461c480d9f041a21b4
{
"Name" : "nameof person",
"_id" : ObjectId("54461c480d9f041a21b4 13460"),
"items" : ["_id" : ObjectId("54461c480d9f041a21b4
{
}
"name" : "Item1",
"count" : 3
}
I tried update with "multi:true" and also "'items.name':{"$in":['Item1'] " (in condition) before posting, but nothing works. kindly help
-KR
}
"count" : 3
}
I tried update with "multi:true" and also "'items.name':{"$in":['Item1']
-KR
}
It's a typo in your update: "nameof person" in the document vs. "name of person" in the update. Note that that condition on Name is redundant given the match on _id.
Yeah true, 'nameof person' was a typo and anyway as you mentioned it is redundant, it was one of the possible combination I was trying, but I am not getting, how to update single item in a sub document,
If some one stuck with the same problem , here is the solution
http://www.wiredprairie.us/
댓글 없음:
댓글 쓰기