Why does this update request update only one record
$coll->update( array( "uid"=(int)$uid, "status"=>1, "time"=>array('$gt'=>0,'$lte'=>$time) ), array( '$set'=>array("status"=>0) ) ); If you cannot read PHP, the CLI version is above code:
db.we.update({"uid":1,"status":1,"time":{"$lte":1324403899}},{"$set":{status:0}}) where time is an integer time and the status is int 0 or 1.
This is the default behavior for MongoDB for updates. If you want to update several documents at once, you obviously need to provide the multi flag:
db.collection.update( criteria, objNew, upsert, multi ) so you will need to use
db.we.update({"uid":1, "status":1, "time" : {"$lte":1324403899}}, {"$set":{status:0}}, false, true); instead.
From the documentation :
If you are coming from SQL, keep in mind that by default update () only modifies the first matching object. If you want to change all consistent objects, you need to use the multi checkbox.
Seeing that this was done in PHP at the beginning, it can be useful to anyone who uses PHP:
$collection->update( array("uid"=>(int)$uid,"status"=>1,"time"=>array('$gt'=>0,'$lte'=>$time)), //search criteria array('$set'=>array('status'=>0)), //update criteria array('multiple'=>true) //options );