DATAMONGO-2477 - Disable auto index creation by default.
Original pull request: #845.
This commit is contained in:
committed by
Mark Paluch
parent
7bac739146
commit
29f05af733
@@ -392,7 +392,7 @@ Automatic index creation is only done for types annotated with `@Document`.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
To turn automatic index creation _OFF_ please override `autoIndexCreation()` in your configuration.
|
||||
To turn automatic index creation _ON_ please override `autoIndexCreation()` in your configuration.
|
||||
[source,java]
|
||||
----
|
||||
@Configuration
|
||||
@@ -400,7 +400,7 @@ public class Config extends AbstractMongoClientConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean autoIndexCreation() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ...
|
||||
@@ -408,7 +408,7 @@ public class Config extends AbstractMongoClientConfiguration {
|
||||
----
|
||||
====
|
||||
|
||||
IMPORTANT: Automatic index creation will be turned _OFF_ by default with the release of 3.x.
|
||||
IMPORTANT: Automatic index creation is turned _OFF_ by default as of the release of 3.x.
|
||||
We recommend index creation to happen either out of band or as part of the application startup using
|
||||
`IndexOperations`.
|
||||
|
||||
|
||||
@@ -148,6 +148,52 @@ Element | Comment
|
||||
|
||||
== Other Changes
|
||||
|
||||
=== Auto Index Creation
|
||||
|
||||
Annotation based index creation is now turned **OFF** by default and needs to be enabled eg. when relying on `@GeoSpatialIndexed`.
|
||||
|
||||
.Enable Auto Index Creation
|
||||
====
|
||||
|
||||
.XML Namespace
|
||||
[source,xml]
|
||||
----
|
||||
<mongo:mapping-converter auto-index-creation="true" /> <1>
|
||||
----
|
||||
|
||||
.Java Config
|
||||
[source,java]
|
||||
----
|
||||
@Configuration
|
||||
public class Config extends AbstractMongoClientConfiguration {
|
||||
|
||||
@Override
|
||||
protected boolean autoIndexCreation() { <2>
|
||||
return true;
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
----
|
||||
|
||||
.Programmatic
|
||||
[source,java]
|
||||
----
|
||||
MongoDatabaseFactory dbFactory = new SimpleMongoClientDatabaseFactory(...);
|
||||
DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(dbFactory);
|
||||
|
||||
MongoMappingContext mappingContext = new MongoMappingContext();
|
||||
mappingContext.setAutoIndexCreation(true); <3>
|
||||
// ...
|
||||
mappingContext.afterPropertiesSet();
|
||||
|
||||
MongoTemplate template = new MongoTemplate(dbFactory, new MappingMongoConverter(dbRefResolver, mappingContext));
|
||||
----
|
||||
<1> Use the XML namespace attribute `auto-index-creation` on `mapping-converter`.
|
||||
<2> Overrride `autoIndexCreation` via `AbstractMongoClientConfiguration` or `AbstractReactiveMongoClientConfiguration`.
|
||||
<3> Set the flag on `MongoMappingContext`.
|
||||
====
|
||||
|
||||
=== UUID Types
|
||||
|
||||
The MongoDB UUID representation can now be configured with different formats.
|
||||
@@ -157,8 +203,8 @@ This has to be done via `MongoClientSettings` as shown in the snippet below.
|
||||
====
|
||||
[source,java]
|
||||
----
|
||||
|
||||
static class Config extends AbstractMongoClientConfiguration {
|
||||
@Configuration
|
||||
public class Config extends AbstractMongoClientConfiguration {
|
||||
|
||||
@Override
|
||||
public void configureClientSettings(MongoClientSettings.Builder builder) {
|
||||
|
||||
Reference in New Issue
Block a user