MongoDB: atomically pop random element -
There is no way on which temporarily populate a random element of the Mongodebi - like radis (remove and retrieve) pop ?
I have read, but now I need to make sure that the element is removed even when it is received, and it should be done atomically.
I think that as an alternative I was able to push data into an array before the field was sorted, but I really like to get it a random record. Looking at the document of
If there are atoms updated within the collection in Mongo, then with a randomly approach approach Just make sure to query for PRIPIP: Some drivers have $ pop , it seems that it can not be argued, so it either removes the first or the last element of an array.
findAndModify combination:
var rand = Math.rand (); Db.collection.findAndModify ({query: {random: {$ gte: rand}}, remove: true});
random: {$ lt: rand} when returns above
null .
findAndRemove , which remove
with
findAndModify : true .
Comments
Post a Comment