S
S
Snewer2014-06-03 12:16:35
NoSQL
Snewer, 2014-06-03 12:16:35

_id comparison in MongoDB

Hello!
Some data is inserted into the collection. For example messages:

{
"from": num,
"to":num,
"msg", string
}

How to correctly display the 10 most recent messages?
Knowing the id of any message, is it possible to display "10 messages, before the message with _id"?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rpsl, 2014-06-03
@Snewer

From the current object, you can get the creation time with:
Next, you can make a selection with the following construction:
True, I don’t remember how indexes behave with such queries, because I always prefer to store unixtime as a separate field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question