Groups
Groups
Sign in
Groups
Groups
mongodb-user
Conversations
About
Send feedback
Help
how to implement FIFO stack ?
243 views
Skip to first unread message
terbooter
unread,
Mar 15, 2012, 11:38:06 AM
3/15/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
I want to make FIFO stack for messages. To keep last N messages only.
First idea was make empty array of size N
and add new message like this
'$push' => array('outbox' => $message),
'$pop' => array('outbox' => -1)
But such queue dosnt work.
A. Jesse Jiryu Davis
unread,
Mar 15, 2012, 11:51:06 AM
3/15/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongod...@googlegroups.com
Hi, when you say it doesn't work, what behavior are you seeing? On the shell, push / pop syntax is like:
> db.foo.insert({'a':[]})
> db.foo.update({}, {$push:{'a':1}})
> db.foo.find()
{ "_id" : ObjectId("4f620f42781a45d79b8c4ff1"), "a" : [ 1 ] }
> db.foo.update({}, {$push:{'a':2}})
> db.foo.find()
{ "_id" : ObjectId("4f620f42781a45d79b8c4ff1"), "a" : [ 1, 2 ] }
> db.foo.update({}, {$pop:{'a':-1}})
> db.foo.find()
{ "_id" : ObjectId("4f620f42781a45d79b8c4ff1"), "a" : [ 2 ] }
mamu
unread,
Apr 30, 2012, 3:56:54 PM
4/30/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongod...@googlegroups.com
You are looking for capped collections. use document insert remove instead of push pop, push pop is for a document only.
http://www.mongodb.org/display/DOCS/Capped+Collections
On Thursday, March 15, 2012 11:38:06 AM UTC-4, terbooter wrote:
Reply all
Reply to author
Forward
0 new messages