Announcement Announcement Module
Collapse
No announcement yet.
Querying MongoDB for array size Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Querying MongoDB for array size

    Hi.

    I want to query objects by their size of a collection/array.

    I tried this in the repository interface:

    Code:
    @Query(value="{}", fields="{ categories : { $size : 0 }}")
    List<Deal> findAllWithNoCategories();
    But that leads to this:


    Code:
    org.springframework.data.mongodb.UncategorizedMongoDbException: Unsupported projection option: $size; nested exception is com.mongodb.MongoException: Unsupported projection option: $size
    	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.repository.query.AbstractMongoQuery$Execution.readCollection(AbstractMongoQuery.java:125)
    	at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$CollectionExecution.execute(AbstractMongoQuery.java:142)
    	at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:88)
    	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:302)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy19.findAllWithNoCategories(Unknown Source)

    Any ideas what I'm doing wrong?
Working...
X