node.js - 在 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 聚合查询。
解决方案
推荐阅读
- sql - 加入具有多个值的不同列时获得相同的结果
- pytorch - 如何在 torch.nn.parallel.DistributedDataParallel 中设置环境变量?
- javascript - 如何使用 JavaScript 在测验中使用单选按钮?
- ionic-framework - 如何在 Cordova、Ionic 和 ASP .NET WebApi 中实现正确的外部身份验证 - Google/Facebook
- python - 在 python 方法中编写就地选项的最佳方法
- python - 加载 Django CSS 时出现 Mime 类型错误
- sql-server - 具有可选参数的不同过滤方法的性能
- rust - 如何正确区分借位和搬家?
- c - 在不同的源文件中使用全局枚举成员
- c# - WPF 左键单击并拖动