spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.

Home Page:https://spring.io/projects/spring-data-mongodb/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IndexInfo does not expose background option of the index

debugmaster opened this issue · comments

While working with MongoOperations and IndexOperations, and it hard to validate when an index has been created with background or not.

Mongo version: 7.0.12
SpringData MongoDB version: 4.2.4

Simple Java Code:

IndexDefinition definition = new Index()
        .on("field", Sort.Direction.ASC)
        .background();
mongoOperations.indexOps(IndexedClass.class).ensureIndex(indexDefinition);

mongoOperations.indexOps(IndexedClass.class).getIndexInfo();
// No way to validate whether background option exists on the index

Looking at Mongo, it seems to keep track of it:

db.getCollection('indexedClass').getIndexes()
[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  { v: 2, key: { field: 1 }, name: 'field_1', background: true }
]

Please include background property to IndexInfo

Thank you @debugmaster for getting in touch - if you've got time to submit a PR we'd be happy to review the changes.