I'm trying to write JSON based mongo queries in my repository class which ends up with an "$and expression must be a nonempty array" exception. I'm using spring-data-mongodb v1.0.1.RELEASE with spring v3.1.0.RELEASE.
Take the following example (I know it's not necessary to use @Query to achieve this, but it's to prove the concept):
When I debug I can see the following query in MongoTemplate:Code:@Query("{ $and: [ { requesterId: ?0 }, { receiverId: ?1 } ] }") public boolean hasRelationship(String user1Id, String user2Id);
The "0" and "1" seems kind of odd to me?Code:$and={ "0" : { "requesterId" : "4f4373aa300439b4e215bff6"} , "1" : { "receiverId" : "4f4373aa300439b4e215bff7"}}
Full stacktrace is:
Code:org.springframework.data.mongodb.UncategorizedMongoDbException: $and expression must be a nonempty array; nested exception is com.mongodb.MongoException: $and expression must be a nonempty array at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:70) at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:1538) at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1449) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1259) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1248) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:471) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:458) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:450) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$SingleEntityExecution.execute(AbstractMongoQuery.java:199) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:92) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:301) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)


Reply With Quote
