首页 > 解决方案 > 在 mongodb 和 nodejs 中搜索文本并返回其相对路径?

问题描述

我的 mongodb 集合中有这样的文档:

{
  client: "shopclues",
  category: "Men",
  category1: " cotton",
  article_type: "cotton wear",
  attribute_values: ["jeans", "cotton jersey", "silk", "leopard print"]
}
{
  client: "shopclues",
  category: "Women",
  category1: "Topwear",
  category2: "Cotton clothes"
  article_type: "Shirts",
  attribute_values: ["denim", "cotton", "multicolor"]
}

输入

{
  text: "cotton",
  client: "shopclues"
}

输出

{
 categories: [
    { path: ["Men"], value: "cotton" }, // matched at path men->category1
    { path: 'Women, "Topwear' }, value: "Cotton clothes" } // at women->category1->category2
  ],
  article_types: [
    { path:["Men", "cotton"], value:"cotton wear" }
  ],
  attribute_values: {
    { path: ["Men", "cotton", "cotton wear"], value: "cotton jersey" },
    { path: ["Women", "Topwear", "Cotton clothes", "Shirts"], value: "cotton" }
  }
}

有人可以帮我写一个本机 mongodb 聚合查询。

标签: node.jsmongodbmongodb-querytaxonomy

解决方案


推荐阅读