0

I want to find two different entries in my MongoDB Collection. Then I want to get all the entries that lie between these two.

e.g.

_id: 1 pet: cat

_id: 2 pet: dog

_id : 3 pet: cow

_id: 4 pet: rabbit

_id: 5 pet: crocodile

_id: 6 pet: Pig

Now I want to get all the data between crocodile and dog => I get Dog, Cow, Rabbit, Crocodile.

How does the model.find() function look like?

Thanks in advance!

  • 1
    is the _id always numeric? do you know the _id before hand? have you made an attempt? – depperm Feb 24 '22 at 15:13
  • @depperm I refer to the default mongodb _ids. So these cannot be used to calculate the difference. I have objects in my collection that have a datetime, which is just a string. I cannot use that to create a query. But the objects in my collection are sorted by datetime. So I want to find two dates in the collection and then get all the values that lie in between – Freadwalker Feb 24 '22 at 15:22
  • Does this answer your question? [Find objects between two dates MongoDB](https://stackoverflow.com/questions/2943222/find-objects-between-two-dates-mongodb) – depperm Feb 24 '22 at 15:24
  • see also: https://stackoverflow.com/q/37686318/3462319 – depperm Feb 24 '22 at 15:25

0 Answers0