例如db.products.createIndex({“item”:1,“stock”:1})
引自https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/
You can specify a sort on all the keys of the index or on a subset; however, the sort keys must be listed in the same order as they appear in the index.
由于javascript对象中没有订单,mongodb如何从中获取订单?
答案 0 :(得分:1)
实际上,在mongo shell(SpiderMonkey)使用的Javascript引擎中,对象中字段的顺序被保留。当你在mongo shell中调用“createIndex”时,shell会以正确的顺序构造一个包含字段的BSON对象,并将createIndexes命令发送到MongoDB。