-
Notifications
You must be signed in to change notification settings - Fork 94
Closed
Description
Hi, I'm seeing an error when attempting to apply an array operator on the result of a string $split.
If I run an aggregation like this:
db.MY_DOC.aggregate([
{
$addFields: {
pathSegments: {
$split: ["$path", "/"]
},
firstSegment: {
$arrayElemAt: ["$pathSegments", 0]
}
}
}
])
I see an error like this:
MongoServerError: PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;
When I run from a java environment, I get this error
org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 28689 (Location28689): 'PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;' on server localhost:12345. The full response is {"$err": "PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;", "errmsg": "PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;", "code": 28689, "codeName": "Location28689", "ok": 0}; nested exception is com.mongodb.MongoCommandException: Command failed with error 28689 (Location28689): 'PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;' on server localhost:12345. The full response is {"$err": "PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;", "errmsg": "PlanExecutor error during aggregation :: caused by :: $arrayElemAt's first argument must be an array, but is [Ljava.lang.String;", "code": 28689, "codeName": "Location28689", "ok": 0}
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:133)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2882)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:564)
at org.springframework.data.mongodb.core.MongoTemplate.doAggregate(MongoTemplate.java:2130)
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:2099)
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1989)
Looking at the mongo-java-server code. It looks like $arrayElemAt is expecting a List type, but the $split return type is a String[]:
mongo-java-server/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Expression.java
Line 1382 in e9394f7
| return ((String) string).split(Pattern.quote((String) delimiter)); |
mongo-java-server/core/src/main/java/de/bwaldvogel/mongo/backend/aggregation/Expression.java
Line 152 in e9394f7
| if (!(firstValue instanceof List<?>)) { |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels