我的mongoDB中有这个结构->
db.Article.save({"_id":ObjectId("90e"),"idPromotion":1,"numArticulos":"3","anyArticle":[{"name":"chair","color":"rojo","price":"10€"},{"name":"table","color":"azul","price":"2€"}],"recibe":"monday"}
db.Article.save({"_id":ObjectId("91e"),"idPromotion":2,"numArticulos":"1","anyArticle":[{"name":"pencil","color":"black","price":"1€"}],"recibe":"monday"}
db.Article.save({"_id":ObjectId("92e"),"idPromotion":3,"numArticulos":"1","anyArticle":[{"name":"car","color":"white","price":"1000€"}],"recibe":"monday"}
对于这个示例,我只需要1。数组“ anyArticle”:请特别注意。
我正在使用SpringBoot --->
型号:
@Document
public class Article{
private Integer idPromotion;
private AnyArticle anyArticle[];
public Article(){}
public Article(Integer idPromotion,AnyArticle anyArticle[]){
this.idPromotion=idPromotion;
this.anyArticle=anyArticle;
}
getters.setter...
}
public class AnyArticle {
private String name;
private String color;
private String price;
constructor, getter, setters...
}
我正在我的serviceImpl中实现此接口
@Repository
public interface ArticleRepository extends CrudRepository<Article, String> {
}
最后我的serviceImpl->
@Autowired
private ArticleRepository repo;
...
List<Article> list = (List<Article>) repo.findAll();
我知道
public interface ArticleRepository extends CrudRepository<Article, String> {
public List<Article> findByIdPromotion(Integer idPromotion);
I get the register with IdPromotion "x"
or
public List<Article> findByRecibe(String Recibe);
}
我的问题是何时尝试获取
public List<Article> findByAnyArticle.name (String name);`
我在Eclipse中“”附近出现错误。我不能使用@Query,因为它是mongoDB,那么我该如何过滤名称或类AnyArticle中的内容?谢谢
编辑,例如我写
public List<Article> findByAnyArticle.name (String name)
名字是椅子,然后我想要这个对象->
{"_id":ObjectId("90e"),"idPromotion":1,"numArticulos":"3","anyArticle":[{"name":"chair","color":"rojo","price":"10€"},{"name":"table","color":"azul","price":"2€"}],"recibe":"monday"}
我想要所有对象,因为在anyArticle中都存在一个带有“椅子”的名称。