根据使用 MongoDB 的产品获取价格范围?

问题描述 投票:0回答:1

我的产品在 Mongo 系列中维护。

请建议一个 Mongo 查询,它将根据可用产品的数量及其相应的价格获取价格范围。我有以下产品系列:

[
  {
    "_id": "563b2574db70394054f35dc5",
    "category": {
      "id": "101010"
    },
    "brand": {
      "name": "Global Desi"
    },
    "is_active": true,
    "parent_sku": "88903689927175",
    "price": 1234,
    "sku": "1321asas",
    "name": "Buddha print kurta",
    "quantity": 1
  },
  {
    "_id": "563b2574db70394054f35dc6",
    "category": {
      "id": "101010"
    },
    "brand": {
      "name": "Global Desi"
    },
    "is_active": true,
    "parent_sku": "88903689927175",
    "price": 5678,
    "sku": "1322asas",
    "name": "Buddha print kurta",
    "quantity": 1
  },
  {
    "_id": "563b2574db70394054f35dc7",
    "category": {
      "id": "101010"
    },
    "brand": {
      "name": "Global Desi"
    },
    "is_active": true,
    "parent_sku": "88903689927175",
    "price": 2345,
    "sku": "1323asas",
    "name": "Buddha print kurta",
    "quantity": 1
  },
  {
    "_id": "563b2574db70394054f35dc8",
    "category": {
      "id": "101010"
    },
    "brand": {
      "name": "Global Desi"
    },
    "is_active": true,
    "parent_sku": "88903689927175",
    "price": 7890,
    "sku": "1324asas",
    "name": "Buddha print kurta",
    "quantity": 1
  }
]
node.js mongodb
1个回答
3
投票

范围 501 - 1000,例如:

   db.collection.find({price: {$gte: 501, $lte: 1000}}).sort({price:1})
© www.soinside.com 2019 - 2024. All rights reserved.