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

Spring Boot 3.x.x + MongoDB: Expression $isArray takes exactly 1 arguments. 2 were passed in. #293

Closed
keelfy opened this issue May 20, 2023 · 4 comments · Fixed by #294
Closed
Labels
bug Something isn't working

Comments

@keelfy
Copy link

keelfy commented May 20, 2023

I'm trying to filter entities by id list.
It looks like this as request param:
filter=id in ['8227848e-9a01-4394-a1e7-1973199c327d', '634c41a4-df95-4669-91e0-d2c49fea5ccd']
...also it occurs with filter=id not in []

And when a request is received, spring-data-mongodb throws an exception:

Spoiler warning
DEBUG 87142 --- [nio-8081-exec-7] o.s.data.mongodb.core.MongoTemplate      : find using query: { "$expr" : { "$and" : [{ "$isArray" : ["8227848e-9a01-4394-a1e7-1973199c327d", "634c41a4-df95-4669-91e0-d2c49fea5ccd"]}, { "$in" : ["$id", ["8227848e-9a01-4394-a1e7-1973199c327d", "634c41a4-df95-4669-91e0-d2c49fea5ccd"]]}]}} fields: Document{{}}
ERROR 87142 --- [nio-8081-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 16020 (Location16020): 'Expression $isArray takes exactly 1 arguments. 2 were passed in.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Expression $isArray takes exactly 1 arguments. 2 were passed in.", "code": 16020, "codeName": "Location16020"}] with root cause
com.mongodb.MongoQueryException: Command failed with error 16020 (Location16020): 'Expression $isArray takes exactly 1 arguments. 2 were passed in.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Expression $isArray takes exactly 1 arguments. 2 were passed in.", "code": 16020, "codeName": "Location16020"}
	at com.mongodb.internal.operation.FindOperation.lambda$execute$1(FindOperation.java:336) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$0(OperationHelper.java:356) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:381) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$1(OperationHelper.java:355) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:381) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:354) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.FindOperation.lambda$execute$2(FindOperation.java:329) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:67) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:340) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:79) ~[mongodb-driver-core-4.8.2.jar:na]
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:191) ~[mongodb-driver-sync-4.8.2.jar:na]
	at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:133) ~[mongodb-driver-sync-4.8.2.jar:na]
	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:90) ~[mongodb-driver-sync-4.8.2.jar:na]
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2728) ~[spring-data-mongodb-4.0.1.jar:4.0.1]
	at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2445) ~[spring-data-mongodb-4.0.1.jar:4.0.1]
	at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2427) ~[spring-data-mongodb-4.0.1.jar:4.0.1]
	at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:833) ~[spring-data-mongodb-4.0.1.jar:4.0.1]
	at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:823) ~[spring-data-mongodb-4.0.1.jar:4.0.1]
	at org.keelfy.storydale.api.service.impl.LanguageServiceImpl.search(LanguageServiceImpl.java:37) ~[classes/:na]
	at org.keelfy.storydale.api.controller.impl.LanguageControllerImpl.search(LanguageControllerImpl.java:29) ~[classes/:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:134) ~[spring-context-6.0.4.jar:6.0.4]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:703) ~[spring-aop-6.0.4.jar:6.0.4]
	at org.keelfy.storydale.api.controller.impl.LanguageControllerImpl$$SpringCGLIB$$0.search(<generated>) ~[classes/:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:207) ~[spring-web-6.0.4.jar:6.0.4]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:152) ~[spring-web-6.0.4.jar:6.0.4]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-6.0.4.jar:6.0.4]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:884) ~[spring-webmvc-6.0.4.jar:6.0.4]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-6.0.4.jar:6.0.4]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.0.4.jar:6.0.4]

Also here is the code that executes mongoOperations.find:

@Override
public Page<Language> search(@NonNull Query query, @NonNull Pageable pageable) {
     final var list = mongoOperations.find(query.with(pageable), Language.class);
     return PageableExecutionUtils.getPage(list, pageable,
             () -> mongoOperations.count(Query.of(query.with(pageable)).limit(-1).skip(-1), Language.class));
 }
@torshid torshid added the bug Something isn't working label May 21, 2023
@torshid
Copy link
Member

torshid commented May 21, 2023

Hello @keelfy,

Fixed in release https://github.com/turkraft/springfilter/releases/tag/3.1.0.

@torshid
Copy link
Member

torshid commented May 21, 2023

Seems like there was an error while releasing to Maven Central. Will try to check later today.

@torshid
Copy link
Member

torshid commented May 21, 2023

3.1.0 is now available.

@keelfy
Copy link
Author

keelfy commented May 21, 2023

Thank you!

3.1.0 is now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants