You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an object type that is stored in MongoDB under two tables: one using the default (class) table name, another using a custom name. The code needs to ensure a geospatial index exists on the table before doing a “near” query. It looks something like this:
$geoNear requires a 2d or 2dsphere index, but none were found' on server localhost:27017
and checking the tables in mongosh I found the index was created on the “place” table, not on “topPlaces”. I traced the fault down to this line in DefaultIndexOperations.execute(callback):
which prioritizes executing the callback for the type of the collection if present over the collectionName.
If this is the intended behavior of indexOps(collectionName, type), it’s not documented. The javadoc implies that the type parameter is only used for field mapping. It also says that collectionName is required, even though it isn’t used.
(Caveat: I’m currently running with spring-data-mongodb 4.0.12, but it appears this execute method has not been changed in the latest code here on GitHub.)
The text was updated successfully, but these errors were encountered:
execute(Class<?> entityClass, CollectionCallback<T> callback) merely derives the collection name from a given type. While this can be useful for cases where the collection name is dynamic (e.g. by using SpEL expressions), we should rather capture the collection name that was given during index operations creations. The reactive counterpart of index operations sticks already to the given collection name.
That being said, I consider this behavior a bug.
mp911de
changed the title
MongoTemplate.indexOps(collectionName, type) ignores collectionName when type is not nullMongoTemplate.indexOps(collectionName, type) ignores collectionName when type is not nullMay 16, 2024
I have an object type that is stored in MongoDB under two tables: one using the default (class) table name, another using a custom name. The code needs to ensure a geospatial index exists on the table before doing a “near” query. It looks something like this:
When executing the query, it fails with:
and checking the tables in mongosh I found the index was created on the “place” table, not on “topPlaces”. I traced the fault down to this line in
DefaultIndexOperations.execute(callback)
:spring-data-mongodb/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java
Line 212 in 7821c2a
which prioritizes executing the callback for the
type
of the collection if present over thecollectionName
.If this is the intended behavior of
indexOps(collectionName, type)
, it’s not documented. The javadoc implies that thetype
parameter is only used for field mapping. It also says thatcollectionName
is required, even though it isn’t used.(Caveat: I’m currently running with spring-data-mongodb 4.0.12, but it appears this
execute
method has not been changed in the latest code here on GitHub.)The text was updated successfully, but these errors were encountered: