To define a compound index:
db.collection.ensureIndex( { orderDate: 1, zipcode: -1 } )
It suddenly dawned on me : are the fields of a JS object ordered? Is there an implicit assumption that orderDate comes first? I'm quite surprised it doesn't use an array instead.
For mongoose, we use :
schema.index({a:1, b:1})
How can we ensure this object is transmitted to the mongo server with the fields ordered as specified in the code?
This post says fields are not ordered. Does JavaScript Guarantee Object Property Order?
Is it acceptable style for Node.js libraries to rely on object key order?