unicloud 模糊查询

const db = uniCloud.database();
const work = db.collection('workIndex')
const food = db.collection('centerFoodList')
//  food.limit().get() 
//  .doc.remove
//  .where().get
//  .count  gt lt eq 
//  or
//  1 简单查询 collection aggregate geoNear doc where field groupBy groupField
//  2 联表查询 collection  geoNear where field  orderBy  skip limit  getTemp 
//  新增  add
//  修改  .doc(id).update({}) or   doc 只能用于id 字符串即可 where 多参数
//  删除  remove
module.exports = {
	async getIndex() {
		const clientInfo = this.getClientInfo()
		const userToken = this.getUniIdToken()
		return {
			status: true,
			data: await work.get()
		}
	},
	async getFoodList() {

		return {
			status: true,
			data: await food.get()
		}
	},
	async getFoodDetail(data) {

		return {
			status: true,
			data: await food.where({
				_id: data.id
			}).get()
		}
	},
	// 搜素食物名
	async searchFood(value) {
		return {
			status: true,
			// data: await food.where({
			// 	name: data
			// }).get()
			data: await food.where({
				name: {
					$regex: '.*' + value,
					$options: 'i'
				}
			}).get()
			// data: await food.where(`${new RegExp(value)}.test('肉')`).get(),
		}
	},
}
posted on 2022-12-16 11:58  哼着老调调  阅读(92)  评论(1编辑  收藏  举报

聊天   切换waifu!  换衣服!   拍照!   许愿吧cxy