After installing Robo3T (previously known as robomongo), a GUI for mongo db, I wanted to add a custom function to retrieve the last N documents in normal order. The query statement I used was:
db.getCollection('i1801').find().skip(db.getCollection('i1801').count() - 1200)
I came across a solution on stackoverflow (mongodb: how to get the last N records?) where it was suggested to create a function like this:
function last(N) {
return db.collection.find().skip(db.collection.count() - N);
}
When I tried to add this custom function last()
in Robo3T, it didn't work as expected. Nothing appeared under the function tab.
I have included some screenshots to show the issue:
https://i.sstatic.net/yoGUl.png
https://i.sstatic.net/CtM1l.png
https://i.sstatic.net/FD6jc.png
Even after clicking the save button, nothing changed. There were still no functions displayed under the function tab. The log indicated that the function last
was created, and the function tab was refreshed.
https://i.sstatic.net/fdxcQ.png
So, I'm wondering how I can successfully add the last
function here?