I have a document in ArangoDB. I need to receive the previous document. How can I receive the previous document in the Arango collection?
Asked
Active
Viewed 91 times
2
-
What exactly do you mean by *previous* or *next* document? Do you mean the temporally previous or next documents inserted or updated in the same collection? – stj Jan 12 '15 at 07:56
-
If you're only after accessing documents first inserted or last inserted, the commands `db.collection.first()` or `db.collection.last()` might be useful. – stj Jan 12 '15 at 07:58
1 Answers
1
My Way is:
FOR d IN MyCollection
FILTER TO_NUMBER(d._key) < 512989295537
SORT d._key DESC LIMIT 1
RETURN d._key
But, I think it is not optimal...
-
3That query will do a full scan of the collection and not use any indexes. If you could store some additional value on insert in another attribute (e.g. `counter`, which will always be increasing), then you could skiplist-index that attribute and run the query on it. That would also be efficient as that could use an index then. – stj Jan 12 '15 at 10:46