小程序云開發(fā)模糊查詢夸盟,實現(xiàn)數(shù)據庫字段的模糊搜索
const db = wx.cloud.database(); //初始化數(shù)據庫
db.collection("goods").where({
goodsname:{
$regex:'.*土豆',
$options: 'i'
}
}).get({
});
查詢goods表中 字段為goodsname中 like='土豆'的商品
后面的$options:'i' 代表這個like的條件不區(qū)分大小寫
實現(xiàn)結果
[
{
"_id": "79550af260584ecb0b4ebae9324d66de",
"content": "來自寧夏本地的土豆,口感密實碾褂,配以油炸雞柳结序,清脆可口梅掠,下飯必備",
"goodsname": "一號窗口-土豆炒雞柳",
"image": "http://inews.gtimg.com/newsapp_bt/0/8184801893/640",
"price": "4",
"store": "和苑餐廳",
"type": "主食"
}
]