mercredi 22 juillet 2020

How to select a random document in MongoDB and find 5 next/preceding documents?

I have a database with Facebook messages and I want to find a random message and also get the 5 next and the 5 preceding messages. Every document has the following template:

_id: ObjectId("5ea27f2d13d10327b2c55bdd")
author : "William"
content : "Hi everybody"
timestamp : 1587502921452
type : "Generic"

They all have the timestamp so it would be possible to sort them by timestamp.




Aucun commentaire:

Enregistrer un commentaire