使用 mongoDB 聚合按文本搜索
我正在尝试对 MongoDB Compass 中名为 DAFacility
的集合进行文本搜索:
_id:62170597b3fa8994a0d9a0c8
author:"User"
organizationName:"TSTT"
eventName:"Facility Assessment After Disaster"
eventDate:2022-02-01T00:00:00.000+00:00
area:"Siparia"
disasterNature:"Earthquake"
threatLevel:"High"
surroundingDamage:"Cracked Foundations and Roads"
facilityName:"Point Lisas Main Facility"
facLocation:Array
facStatus:"Operable"
operEqu:23
inoperEqu:7
facilityDamage:"Cracked Walls and Floors"
facImage:Array
__v:0
我正在尝试搜索字段 facilityDamage
,我可以在其中从整个数据中搜索一个单词条目(例如搜索单词 "Walls"
并显示整个条目)
我尝试在 mongoDB 数据聚合选项中执行它,模板为:
[
{
'$search': {
'index': 'string',
'text': {
'query': 'string',
'path': 'string'
}
}
}
]
我已阅读该文档,这让我更加困惑至于里面有什么索引、查询和路径。 你们能告诉我索引、查询和路径中包含哪些变量吗?
每当我在节点中使用它时,它都会返回一个空数组:
exports.DAEquipment_damage_search = (req, res) => {
DAEquipment.aggregate([
[
{
'$match': {
'$or': [
{'facilityDamage':{ '$regex':'.*' + req.body.facilityDamage + '.*','$options': 'i' } }
]
}
}
}
]
]).then((DAEquipment) => {
res.send(DAEquipment);
console.log(DAEquipment);
})
.catch((e) => {
res.send(e);
});
};
I am trying to do a text search of the collection called DAFacility
in MongoDB Compass:
_id:62170597b3fa8994a0d9a0c8
author:"User"
organizationName:"TSTT"
eventName:"Facility Assessment After Disaster"
eventDate:2022-02-01T00:00:00.000+00:00
area:"Siparia"
disasterNature:"Earthquake"
threatLevel:"High"
surroundingDamage:"Cracked Foundations and Roads"
facilityName:"Point Lisas Main Facility"
facLocation:Array
facStatus:"Operable"
operEqu:23
inoperEqu:7
facilityDamage:"Cracked Walls and Floors"
facImage:Array
__v:0
I am trying to search the field facilityDamage
where i can search maybe one word from the entire data entry (eg searching the word "Walls"
and having the entire entry shows up)
I am trying to perform it within mongoDB data aggregation option with the template being:
[
{
'$search': {
'index': 'string',
'text': {
'query': 'string',
'path': 'string'
}
}
}
]
I have read the document which got me more confused as to what goes in the index, query and path.
can you all advise me as to what variables goes into index, query and path.
Whenever i use it within node it returns an empty array:
exports.DAEquipment_damage_search = (req, res) => {
DAEquipment.aggregate([
[
{
'$match': {
'$or': [
{'facilityDamage':{ '$regex':'.*' + req.body.facilityDamage + '.*','$options': 'i' } }
]
}
}
}
]
]).then((DAEquipment) => {
res.send(DAEquipment);
console.log(DAEquipment);
})
.catch((e) => {
res.send(e);
});
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
愿它能帮助你
May it will help you