Reputation: 367
I want to update the document with or where condition. (i.e) the condition has to look out on multiple data on the document Example: Consider the following documents
{
'sender' => '123456',
'receiver' => '654321',
'reply_time' => '2 sec'
}
{
'sender' => '654321',
'receiver' => '123456',
'reply_time' => '10 sec'
}
{
'sender' => '123456',
'receiver' => '78945612',
'reply_time' => '10 sec'
}
In this, I want to update 'reply_time' to particular value where the 'sender' is '123456' or 'receiver' is '123456', Is there any way to achieve it by using update query or any any other possible ways ?
Upvotes: 1
Views: 513
Reputation: 1957
Try the following query:
db.collection.update(
{
$or : [ { "sender" : "123456" }, {"receiver" : "123456"} ]
},
{
$set: { "reply_time" : <reply_time> }
}
)
If you want to update multiple documents, use updateMany.
Hope this helps.
Upvotes: 2