{ "_id" : ObjectId("5bee629dee0fc9d332b2107b"), "no" : NumberLong(30001), "name" : "레몬과일가게", "products" : [ { "id" : NumberLong(50001), "name" : "레몬", "price" : NumberInt(4), }, { "id" : NumberLong(50002), "name" : "사과", "price" : NumberInt(12), }, { "id" : NumberLong(50003), "name" : "파인애플", "price" : NumberInt(3), }, { "id" : NumberLong(50004), "name" : "귤", "price" : NumberInt(3), } ] } |
mongodb 에서 30001번 과일가게에서 레몬의 가격을 변경하기 위한 코드 샘플
var filter = Builders<store>.Filter.Where(c => c.no == 30001 && c.products.Any(e => e.id == 50001)); var update = Builders<player>.Update.Set(x => x.products[-1].price, 2000); var option = new UpdateOptions() { IsUpsert = false }; |
출처 : https://stackoverflow.com/questions/31453681/mongo-update-array-element-net-driver-2-0
https://stackoverflow.com/questions/31277679/how-to-find-and-update-an-item-inside-of-a-array-of-an-object-in-an-array-acc