如何在 Spring 中使用 @Query 注解来查询 mongo Document 中的数组。 例如:
user_id : 1
tags : ['scientist','biologist','mathematician','chemist'];
user_id : 1
tags : ['scientist','physicist','carpenter','chemist'];
我正在查询 API,URL 是这样的:
localhost:8080/tags=scientist,biologist // should return 1st document
或
localhost:8080/tags=physicist,carpenter // should return 2nd document
url 中可以有任意数量的标签,并且标签数组必须包含 url 中存在的所有标签。 我怎样才能实现这个目标?
最佳答案
您可以尝试使用 $or
的查询注释 运算符为
@Query("{'$or' : [{ 'tags': ?0, 'tags': ?1 }]}")
public List<Tags> findByTagsFirstorSecond(string firstTag, string secondTag);
关于java - mongo 中的所有操作符均使用 Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111326/