有没有办法执行 list(List<ObjectId> id) 来查找与列表匹配的文档?

Is there a way to execute a list(List<ObjectId> id) to find documents that match the list?

我正在使用 Panache 存储库策略将数据保存在 MongoDB 数据库中。

@ApplicationScoped
public class ProductRepository implements PanacheMongoRepository<Product> {}

假设我有一个包含以下数据的集合。

|id  | name | price |
|1   | p1   | $ 1.00|
|2   | p2   | $ 2.00|
|3   | p3   | $ 3.00|
|4   | p4   | $ 4.00|

我有一个 List<ObjectId> productsToRetrieve 和 [1, 3]

查询的预期结果为:

id name price
1 p1 $ 1.00
3 p3 $ 3.00

这是我试过的方法

find("id", productsToRetrieve);
find("id = ?1", productsToRetrieve);
list("id", productsToRetrieve);
Document query = new Document();
find(new Document("id", new Document("$in", productsId))).list();

我可以使用 forEach 从存储库中检索每个产品并添加到列表中,但这不是一个好方法。 PanacheQL 查询可以解决问题,但我不知道如何解决。

要获得所需的输出,必须使用 $in。示例 here.

并使用 quarkus,根据 docs,它说:

status in ?1 will be mapped to {'status':{$in: [?1]}}

所以必要的查询是:

_id in ?1, ?3