question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

indexes not being added for array fields

See original GitHub issue

If 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:closed
  • Created 10 years ago
  • Comments:10

github_iconTop GitHub Comments

7reactions
wavdedcommented, Apr 25, 2014

this seems to work:

 properties : { type: [{ type: ObjectId, ref: 'Property' }], index: true },
4reactions
aheckmanncommented, May 21, 2013

this is by design as you have discovered.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found