在 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 wear"],value: "cotton jersey" },{ path: ["Women","Topwear","Cotton clothes","Shirts"],value: "cotton" }
  }
}

有人可以帮我写一个原生的 mongodb 聚合查询吗..

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)