Similar to SERVER-78140, expose the sort option in the delete command.
Motivation
Some drivers devs adding sort to update API (DRIVERS-2822) were surprised that sort was not available for delete:
const collName = "foo"; const coll = db[collName]; // Can do single-document update with sort. { coll.drop(); coll.insertMany([{ a: 1 }, { a: 2 }]); db.runCommand({ update: collName, updates: [{ q: {}, u: { $inc: { a: 1 } }, multi: false, sort: { a: -1 } }] }); assert(coll.findOne({ a: 3 })) } // Cannot do single-document delete with sort? { coll.drop(); coll.insertMany([{ a: 1 }, { a: 2 }]); db.runCommand({ delete: collName, deletes: [{ q: {}, limit: 1, sort: { a: -1 } }] }); // Throws: MongoServerError: BSON field 'delete.deletes.sort' is an unknown field. }
SERVER-78140 notes "multiple users have asked for this", but I am unsure if there is a similar user need for delete.
- is related to
-
SERVER-78140 allow update to supply sort option
- Closed