我正在嘗試對DAFacilityMongoDB 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
我正在嘗試搜索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);
});
};
uj5u.com熱心網友回復:
await DAFacility.aggregate([
{
$match: {
$or: [
{"facilityDamage":{ $regex:'.*' searchText '.*',$options: 'i' } },
]
}
},
])
愿它能幫助你
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/443292.html
標籤:mongodb 猫鼬 MongoDB指南针
