Java&Mongo: get object where field exist

后端 未结 2 1829
一生所求
一生所求 2021-01-26 03:56

Situation: I have collection with documents, each document contains such fields: \"_id\"(ObjectId), \"userId\"(String), but it also can be field \"files\"(Object).

When

相关标签:
2条回答
  • 2021-01-26 04:36

    You can construct this Query to get all documents that contains files filed:

    Query.query(Criteria.where("files").exists(true))
    
    0 讨论(0)
  • 2021-01-26 04:42

    Another possibility is to use org.springframework.data.mongodb.repository.Query annotation on your method (useful when using MongoRepository):

    @Query(value="{ files : { $exists : true } }")
    
    0 讨论(0)
提交回复
热议问题