Possible to iterate in natural order for a capped collection *from a unique record* in the collection?

33 views
Skip to first unread message

Marko

unread,
Apr 8, 2011, 1:41:20 PM4/8/11
to mongodb-user
I know i can iterate in natural order though a capped collection from
the start or end of the collection.

But can the same be done from an arbitrary record in the collection?

Specifically, if i were to add a unique index to a capped collection,
then query a unique record, then would it be possible to iterate
forward (or backwards) in natural (insert) order from the unique
record?

eg.

if i had an Events capped collection, with a unique "id" attribute.

The event i'm interested in is...

Event eventX = db.Events.findOne({'id': <uniqueID>})

Now is it possible to get the next "N" records in natural order from
eventX?

Thank you.

Kyle Banker

unread,
Apr 8, 2011, 3:10:49 PM4/8/11
to mongod...@googlegroups.com
No, that's not possible, because you'd be mixing a b-tree cursor with
a capped collection cursor.

What's your use case? There may be some features coming out in the
next release that can help with this.

> --
> 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.
>
>

Marko

unread,
Apr 8, 2011, 11:53:36 PM4/8/11
to mongodb-user
Hi Kyle.

My usecase is log-like one. Similar to the example i gave, if a log
contained a list of Events, then i would like to query a particular
event and some number of events following (in insert order).

I could use Event timestamps to solve that, but if i could use the cap
collection natural order, then i would not require the timestamp
index, and i would not be sensitive to a correctly set clock.

Thank you.

Kyle Banker

unread,
Apr 11, 2011, 4:03:02 PM4/11/11
to mongod...@googlegroups.com
Hi Marco,

Right. There's no way to jump directly to a particular record and then
to iterate in order. You may want to file a feature request at
jira.mongodb.org.

Kyle

Reply all
Reply to author
Forward
0 new messages