Skip to content

Collection name based lazy indexing [DATAMONGO-719] #1648

@spring-projects-issues

Description

@spring-projects-issues

Chris Cox opened DATAMONGO-719 and commented

Lazily ensuring indexes based off dbName.collectionName (instead of class type) would be incredibly useful in cases such as collection based multi-tenant systems.

Currently, the MongoPersistenEntityIndexCreator tracked index ensured collections classesSeen. This works very well when the entityClass:collection is 1:1. In cases such as the one mentioned above, a new tenant means a new collection and new indexes. In the current code, Spring Data will at best create a defaulted or "tenantless" collection to index which will likely never be used.

If the index creator instead tracked by a resolved dbName.collectionName pattern, this would cover all mulit-tenant instances. However, it can no longer listen for an MappingContextEvent from the mapping context as this will no longer cover all cases where a new collection is required. It would most likely need to connect to an events on both a (yet to exist) BeforeFindEvent and BeforeSaveEvent and check to see if the target collection has been accessed yet. This cache of accessed collections can be exposed to a distributed caching, but ensuring indexes that already exist should be a minor operation for mongo.

See the referenced URL. The project's workaround branch has a test showing desired functionality and workarounds to the current code to make it possible


Affects: 1.2.1

Reference URL: https://bitbucket.org/ccox/collectionmultitenantpoc

Issue Links:

  • DATAMONGO-841 Indexing do not work properly after collection is dropped

  • DATAMONGO-660 Index not automatically created

  • DATAMONGO-2188 Add configuration option to enable/disable automatic index creation

Referenced from: pull request #754

1 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supportstatus: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions