db.collection.insert({ position: 1 })
db.collection.insert({ position: 2 })
var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } })
db.collection.find({ $or : ids })
---
## 2.4.10
joe@li245-114:~$ mongo
MongoDB shell version: 2.4.10
connecting to: test
> db.collection.insert({ position: 1 })
> db.collection.insert({ position: 2 })
>
> var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } })
> db.collection.find({ $or : ids })
{ "_id" : ObjectId("538748f9b637c258c6964136"), "position" : 2 }
{ "_id" : ObjectId("538748f9b637c258c6964135"), "position" : 1 }
## 2.6.0
> db.collection.insert({ position: 1 })
WriteResult({ "nInserted" : 1 })
> db.collection.insert({ position: 2 })
WriteResult({ "nInserted" : 1 })
>
> var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } })
> db.collection.find({ $or : ids })
{ "_id" : ObjectId("538749a82aa9f7bc4f6dd565"), "position" : 1 }
{ "_id" : ObjectId("538749a82aa9f7bc4f6dd566"), "position" : 2 }