> db.usr.insert({q:['a','b','c','d']})
q가 d인 놈을 찾아서, b로 바꾸어라.
The $ operator (by itself) means "position of the matched array item in the query". Use this to find an array member and then manipulate it.
Currently the $ operator only applies to the first matched item in the query.
> db.usr.update({q : 'd'} , {$set : {"q.$" : 'b'} }, false,false);
> db.usr.find()
{ "_id" : ObjectId("4d81a4f4798c57bb61763ce2"), "q" : [ "a", "b", "c", "d" ] }q가 d인 놈을 찾아서, b로 바꾸어라.
The $ operator (by itself) means "position of the matched array item in the query". Use this to find an array member and then manipulate it.
Currently the $ operator only applies to the first matched item in the query.
> db.usr.update({q : 'd'} , {$set : {"q.$" : 'b'} }, false,false);
> db.usr.find()
{ "_id" : ObjectId("4d81a4f4798c57bb61763ce2"), "q" : [ "a", "b", "c", "b" ] }
> db.rrr.insert( { hi : { q: "aaaa" } , lo : "bbbb" })
> db.rrr.insert( { hi : { q: "aaaa" } , lo : "bbbb" })
> db.rrr.find()
{ "_id" : ObjectId("4d82dbd900cb627342a97515"), "hi" : { "q" : "aaaa" }, "lo" : "bbbb" }
> db.rrr.update( { lo : "bbbb"} , { lo : "aaaa"} )
> db.rrr.find()
{ "_id" : ObjectId("4d82dbd900cb627342a97515"), "lo" : "aaaa" }
$ 오퍼레이션 사용시
. Dot 오퍼레이션 사용시( 따옴표 안한다고 에러라니)
$ 오퍼레이션 사용시
> db.rrr.update( { lo : "bbbb"} , { $set : { lo : "aaaa"}} )
> db.rrr.find()
{ "_id" : ObjectId("4d82dc8600cb627342a97516"), "hi" : { "q" : "aaaa" }, "lo" : "aaaa" } . Dot 오퍼레이션 사용시( 따옴표 안한다고 에러라니)
> db.rrr.update( { hi.q : "aaaa"} , { $set : { lo : "cccc"}} )
Fri Mar 18 13:25:21 SyntaxError: missing : after property id (shell):0
> db.rrr.update( { "hi.q" : "aaaa"} , { $set : { lo : "cccc"}} )
> db.rrr.find()
{ "_id" : ObjectId("4d82dc8600cb627342a97516"), "hi" : { "q" : "aaaa" }, "lo" : "cccc" }
> db.rrr.update( { "hi.q" : "aaaa"} , { $set : { "hi.q" : "cccc"}} ,true, false)
> db.rrr.find()
{ "_id" : ObjectId("4d82dc8600cb627342a97516"), "hi" : { "q" : "cccc" }, "lo" : "cccc" }
{ "_id" : ObjectId("4d82e273e31048d84b4136f9"), "hi" : { "q" : "cccc" } } 
