indexes not being added for array fields
See original GitHub issueIf I have some schema defined like this:
schema = new Schema({_some_array_field: [{type: String, index: true}]})
There’s no index on _some_array_field if I check with getIndexes() from the shell.
I need to explicitly do schema.index({_some_array_field: 1})
UPDATE: It looks like if I specify the array field like this, the index gets applied:
schema = new Schema({_some_array_field: {type: [String], index: true}})
So it seems to be relating to how the index options are being parsed out.
Issue Analytics
- State:
- Created 10 years ago
- Comments:10
Top Results From Across the Web
Mongodb not using index for array of objects - Stack Overflow
The following query will use your index for both of your array fields: .find({ appId: ObjectId("5c6a8ef544ff62c73bdb98fc"), ...
Read more >Index not being used on array elements in JSONB column
I can see in the pg_indexes table that the type of the permissions field seem to be ::text , but I'm not sure...
Read more >Datastore: field types of array are always showing indexed ...
Saving array's shows it is indexed (not all the actual items in the array, just the field), even when excludeFromIndexes: true.
Read more >Multikey Indexes — MongoDB Manual
MongoDB automatically creates a multikey index if any indexed field is an array; you do not need to explicitly specify the multikey type....
Read more >Indexed collections - JavaScript - MDN Web Docs - Mozilla
This chapter introduces collections of data which are ordered by an index value. This includes arrays and array-like constructs such as ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this seems to work:
this is by design as you have discovered.