0

I have a document in a Mongo collection which has an index as follows:

field._ref.$id_1

This is tripping up a new database driver we're planning on using - it doesn't seem to understand this format, and I haven't seen it anywhere else before. There's a chance it could have been automatically created.

Looking at index usage, this index is heavily used. There is also an index on just field_1 which is not used.

field is a reference field, storing references to other documents in other collections.

What is this index and why does it have an odd formatting? If I remove it, would the other index field_1 bear the load?

0

1 Answer 1

0

It looks like you have documents using the older DBRef convention, which uses a subdocument with $-prefixed fields ($ref, $id, and $db) to describe a reference to a document in another collection.

Looking at index usage, this index is heavily used. There is also an index on just field_1 which is not used.

The index on field_1 could be used to match the entire subdocument (including all fields in a consistent order), but the common use case appears to be looking up the _id reference via field._ref.$id_1.

DBRefs have limited support in modern MongoDB driver and server versions and you would definitely be better converting these to manual references with more typical field names.

For example, using field_id to store a manual reference to the _id of a field collection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.