Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Indexed causes Drop and Create Index which impacts applications [DATAMONGO-2657] #3510

Closed
spring-projects-issues opened this issue Nov 19, 2020 · 4 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 19, 2020

HARI opened DATAMONGO-2657 and commented

SpringDataMongo 2.1.8.Release

Mongo DB version 4.0.16-enterprise

Actual result:: Upon Startup of application, Spring Data Mongo  recreates the index even after index being already present 

Expected result: If Index already exists, then the index creation should not happen

Java Class defined::

@Document(collection = "example")
@JsonIgnoreProperties
public class ExampleTO 

{ @Indexed private String textId; }

 

Application has 2 shards, 10 microservices access the same database collection but few applications do not have read prefrences but other applications have read preferences as seconday


Issue Links:

  • DATAMONGO-2477 Disable auto-index creation by default
    ("duplicates")
  • DATAMONGO-2188 Add configuration option to enable/disable automatic index creation
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 19, 2020

Mark Paluch commented

We introduced with Spring Data MongoDB 2.2 a utility to programmatically create indexes and to disable auto-index creation because requirements regarding index creation are very different. Please note that Spring Data MongoDB 2.1 is no longer maintained

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 20, 2020

HARI commented

Thanks Mark Paluch . While we migrate to Spring Data MongoDB 2.2, can you please answer the following questions::

  1. We see Spring Data Mongo calls CreateIndex on Mongo Server on each Restart without first fetching existing indexes on a collection? Is this by design or are we missing anything here?
  2. When Spring Data Mongo initiates an Index creation, will that drop existing index and recreate the index?
  3. Does createIndex command adds the newly inserted records to the Index location since the last indexed time ?

 

Request you to help us with this information so that we can apply a hotfix for now as this is year end and we need to apply a short term fix to remove @Indexed from the Documents

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 20, 2020

Mark Paluch commented

Using @Index annotations in your domain model will cause that Spring Data MongoDB creates indexes upon startup/when interacting with the entity for the first time. That's by design and disabled by default since Spring Data MongoDB 3.0. We're always using MongoCollection.createIndex (previously it was ensureIndex) as that's an idempotent operation.

 

Does createIndex command adds the newly inserted records to the Index location since the last indexed time ?

Not sure I follow. MongoDB indexes newly added documents automatically, without requiring applications to take care about updated or added documents.

We generally use Jira to track bug reports and features. StackOverflow is a better place for general purpose questions. Since this discussion doesn't evolve towards a bug report or a feature request, I'm going to close this ticket

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 20, 2020

HARI commented

Sure thanks for the response. Appreciate it. 

Mark Paluch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants