simulating remove + limit

93 views
Skip to first unread message

Dima Brodsky

unread,
Aug 11, 2010, 7:13:15 PM8/11/10
to mongod...@googlegroups.com
Hi,

I am using mongoDB as a queue and it is working quite well. I am
using findAndModify with the remove flag set to true to return a
single element and immediately remove it from the collection. What
I'd like to do is be able to fetch and delete several items at once,
or atleast to minimize the number of calls done to the mongo server.
What would be the best way to simulate a 'remove' with a limit?

Before mongodb I used mysql and I would do something like:

update jobQ set worker = %s order by insertTime limit 20
select * from jobQ where worker = %s
delete from jobQ where worker = %s

once a set of jobs were assigned to a particular worker there was no
way for another worker to pick them up etc ... I'd like to repro the
above three lines in mongo.

Thanks!
ttyl
Dima

--
ddbr...@gmail.com

"The price of reliability is the pursuit of the utmost simplicity.
It is a price which the very rich find the most hard to pay."

(Sir Antony Hoare, 1980)

Michael Dirolf

unread,
Aug 12, 2010, 4:20:56 PM8/12/10
to mongod...@googlegroups.com
You should be able to use basically that exact same pattern in MongoDB
- make sure to only set worker on documents that don't already have a
worker in your update, since all three operations cannot be done
atomically.

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages