我有一个Mongo集合,其中包含以下文档:
a: { product: 1,country: 2,stock: 1}
b: { product: 1,country: 3,stock: 3}
c: { product: 2,country: 1,stock: 1}
有时候我想获取所有国家的产品库存(所以我先检索所有国家的产品库存,然后添加它们),而有时候我想要某个特定国家的库存。
是否可以制作单个方法,例如:
findByProductAndCountry(Integer product,Integer country)
像这样工作:
findByProductAndCountry(1,2) //returns document a
findByProductAndCountry(1,null) //returns documents a and b
谢谢!