I frequently find myself (for better or worse) using MongoDB Compass to edit documents on the fly. The documents I edit are almost always among the most recent ones created. Subsets of these documents represent an event that takes place on a date.
{
"eventId": 1, // data about the event itself, such as date, is stored in another collection
"title": "My title",
"subtitle": "My subtitle",
/* other fields... */
}
Ideally, when I click the Find button in Compass, it will list the documents in descending order of eventId
, and ascending order of the entry's title
and subtitle
. I've created the index for this:
db.myCollection.createIndex({
eventId: -1,
title": 1,
subtitle: 1
});
Is it possible to tell the MongoDB server to use this index when ordering documents, either during insertion (and then rebuilding the dataset that already exists), or at least to use it when returning results without sort
/$orderby
being specified?
If this is only possible at the time the collection is created, my dataset is small enough that creating a new one and copying over the data would not be an issue.