This question on MongoDB compound index:
Below is a sample document in a given collection test.
{ a : 5, b : 3, c: 2, d : 1 }
Given a compound index { a: 1, b:1, c:1, d:1}, Which of the below query will not use in-memory sorting? Select all valid.
A) db.test.find( { a: 5, b: 3 } ).sort( { c: 1, d : 1 } )
B) db.test.find( { a: 5, b: 3 } ).sort( { a: 1} )
C) db.test.find( { a: 5, b: 3 } ).sort( { a: 1, b: 1, c: 1 } )
D) db.test.find( { a: 5, b: 3 } ).sort( { c: 1 } )
My understanding is A, B, C, D will all be able to use the compound index, without the need for in-memory sorting. However I've asked around, even asked different AI agents, but all have different answers. Would anyone take a shot at answering this?
asked 16 hours ago
lang-sql