首页 > 其他分享 >unicloud 模糊查询

unicloud 模糊查询

时间:2022-12-16 12:14:26浏览次数:36  
标签:await const get food where 模糊 查询 unicloud data

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(),
		}
	},
}

标签:await,const,get,food,where,模糊,查询,unicloud,data
From: https://www.cnblogs.com/caoxueyang/p/16986985.html

相关文章