简体   繁体   English

"MongoDB查询多个特定文档"

[英]MongoDB Query Multiple Specific Documents

I would like to make a single query to my backend database to retrieve a list of results.我想对我的后端数据库进行一次查询以检索结果列表。 These results will have a unique "product_id" and they will also have a "variant_id".这些结果将有一个唯一的“product_id”,它们也将有一个“variant_id”。 Items may share product IDs but must have unique variant IDs.商品可以共享产品 ID,但必须具有唯一的变体 ID。 For Example例如

{
  product_id:"123",
  variant_id:"000"
}

{
  product_id:"123",
  variant_id:"111"
}

{
  product_id:"987",
  variant_id:"000"
}

Simple $or can do the job:简单的 $or 可以完成这项工作:

db.collection.find({
$or: [
 {
  "product_id": "123",
  "variant_id": "000"
 },
 {
  "product_id": "987",
  "variant_id": "000"
 }
]
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM