How could mongodb know an index prefix order from an un-ordered javascript object ?

14 views
Skip to first unread message

Roben

unread,
Feb 21, 2017, 9:57:47 AM2/21/17
to node-mongodb-native
As quoted from https://docs.mongodb.com/manual/core/index-compound/#prefixes
If a query want to use the index it should keep the same order as the index prefix.
The mongo shell and node-mongdb-native driver all use javascript object to make the query and create indexes.
As we all know that there's no order can be get from an javascript object, how could mongodb know it ?

christkv

unread,
Feb 21, 2017, 10:29:34 AM2/21/17
to node-mongodb-native
you have to use ES6 Map or it's polyfill that is included with the driver.

const Map = require('mongodb').Map

this will correctly preserve the order, however Maps are not returned by the driver.

Roben

unread,
Feb 21, 2017, 8:52:03 PM2/21/17
to node-mongodb-native
The node-mongodb-native doc never says that you have to use es6 Map in the find or createIndex API. It all use the plain javascript object in the doc.

在 2017年2月21日星期二 UTC+8下午11:29:34,christkv写道:
Reply all
Reply to author
Forward
0 new messages