Created
September 22, 2019 01:34
-
-
Save w3irdrobot/1f73c20d6018b4bf15a85b4445e81dc0 to your computer and use it in GitHub Desktop.
Get last in Mongo collection and return partial object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.getCollection('collectionName').find().sort({"$natural": -1}).limit(1).map(function(doc) { | |
var obj = {} | |
obj["_id"] = doc._id | |
obj["another_field"] = doc.another_field | |
return obj | |
})[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment