Situation: I have collection with documents, each document contains such fields: \"_id\"(ObjectId), \"userId\"(String), but it also can be field \"files\"(Object).
When
You can construct this Query
to get all documents that contains files
filed:
Query.query(Criteria.where("files").exists(true))
Another possibility is to use org.springframework.data.mongodb.repository.Query
annotation on your method (useful when using MongoRepository
):
@Query(value="{ files : { $exists : true } }")