Skip to content

Instantly share code, notes, and snippets.

@shannonbradshaw
Last active August 5, 2016 21:34
Show Gist options
  • Save shannonbradshaw/b03380ed8ea4d70b78f5e7cef62d26d1 to your computer and use it in GitHub Desktop.
Save shannonbradshaw/b03380ed8ea4d70b78f5e7cef62d26d1 to your computer and use it in GitHub Desktop.
Task: Last 10 Items

Suppose you have a collection called stories containing documents that resemble the following:

{
    _id : ObjectId("579b8063a2f12bdaf5684505"),
    author : "John Henry",
    name : "Building a Railroad"
}

Assume all _id values were automatically generated as the documents were inserted into this collection. In the mongo shell, what query would you use to find the ten most recently inserted documents in this collection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment