Any clues as to why this is? I assume it has something to do with how MongoDB treats the keys internally and I also noticed that the execution plan changed (the one with object using slot-based, the other not).
I haven’t found any examples using an array online, but it yields an identical resultset in our case, just much faster.
Unfortunately without some document example and explain plan output, it’s difficult to determine what’s really going on. This is because MongoDB query planner could tailor its approach depending on how the documents are structured, indexes on the collection, and other information.
Unlike SQL databases with rigid schema, MongoDB does not have the luxury of knowing beforehand the content and datatype of each collection.It will be helpful if you can provide an example document, the output of db.collection.explain('executionStats').aggregate(...) for both queries, the output of db.collection.getIndexes() , and db.collection.stats().
I don’t think any of those commands will print an actual document in their output, only some statistics about the collection and the aggregation’s execution. However we do need an example document to recreate what you’re seeing.