贴一个小程序端db.collection 操作的封装。
封装在utils里
const collectionGet = async function (collectionName, getData = {}) {
let {
where,
skip,
limit
} = getData;
where = where ? where : {};
skip = skip ? skip : 0;
limit = limit ? limit : 5;
wx.showLoading({
title: '加载ing...',
})
try {
const res = await db.collection(collectionName).where(where).skip(skip).limit(limit).get();
return res['data'];
} catch (error) {
return error;
} finally{
wx.hideLoading({
success: (res) => {},
})
}
}
页面调用很方便:
const result_get=await utils.collectionGet("compositions",{
where:{
_id:docid
}
});