javascript 在一个字段上匹配2个集合,如果价格低于,则查找docs,并在mongodb中查找新集合

kupeojn6  于 2023-03-06  发布在  Java
关注(0)|答案(1)|浏览(107)

一月一日

{
  "_id": {
    "$oid": "6402fd80ac80190371cda444"
  },
  "asinno": "B096V2J37X",
  "urunisim": "TOSHIBA 65UA3A63DT ",
  "fiyat": 14485.48
}

col b

{
  "_id": {
    "$oid": "63feef705572f69c3986f085"
  },
  "asinno": "B096V2J37X",
  "urunisim": "TOSHIBA 65UA3A63DT ",
  "fiyat": 11909.99
}

如你所见,匹配asin字段上的集合,然后查找如果colb.fiyat lt cola.fiyat,将结果作为新集合输出

a.aggregate[
    {
      $lookup:
         {
          from: "b",
          localField: "asinno",
          foreignField: "asinno",
          as: "result",
        },
    },
    {
      $match:
        /**
         * query: The query in MQL.
         */
        {
          $expr: {
            $lt: ["$result.fiyat", "$fiyat"],
          },
        },
    },
  ]

这是我的代码,但它给出错误

PlanExecutor error during aggregation :: caused by :: operation
exceeded time limit

当我增加限制也给出相同的错误有更快的方法来排序吗?因为两个集合都有超过600k的文档

c9qzyr3d

c9qzyr3d1#

[
        {
          $lookup: {
            from: "b",
            localField: "asinno",
            foreignField: "asinno",
            as: "result",
          },
        },
        {
          $unwind:
            {
              path: "$result",
            },
        },
        {
          $match:
            {
              $expr: {
                $lt: ["$result.fiyat", "$fiyat"],
              },
            },
        },
        {
          $out:
            "urun6-7",
        },
      ]

$unrella解决了我的问题,但仍然需要速度。有什么建议吗?

相关问题