赞
踩
这个作业属于哪个课程 | 2023软件工程实践W班 |
---|---|
这个作业要求在哪里 | 软件工程实践总结&个人技术博客 |
这个作业的目标 | 课程回顾与总结 个人技术总结 |
其他参考文献 | 《构建之法》 |
在云函数根目录右键点击新建node.js云函数
在新建的云函数处右键在终端打开
编写云函数内容
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 const db = cloud.database(); // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext()//目的:获取_openid try { return await db.collection("order").add({ data: { normalUser: wxContext.OPENID,//获取操作者_openid的方法 } }) } catch (e) { console.log(e) } }
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 const db = cloud.database(); const _ = db.command //引用指令 // 云函数入口函数 exports.main = async (event, context) => { try { return await db.collection("order").where({ orderState:event.orderState, }) .delete({ data: { doneTime: event.doneTime, orderState: "已完成" } }) } catch (e) { console.error(e) } }
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 const db = cloud.database(); const _ = db.command //引用指令 // 云函数入口函数 exports.main = async (event, context) => { try { return await db.collection("order").where({ orderState:event.orderState, }) .update({ data: { doneTime: event.doneTime, orderState: "已完成" } }) } catch (e) { console.error(e) } }
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
try {
return await db.collection('order' ).where({
orderState:event.orderState,
}).get();
} catch (e) {
console.error(e);
}
}
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 const db = cloud.database() // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() try { //order return await db.collection('order').where({ orderState:"待接单", }) .field({ 'name': true }) .get(); } catch (e) { console.error(e); } }
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 const db = cloud.database() const $ = db.command.aggregate // 云函数入口函数 exports.main = async (event, context) => { return await db.collection('user_record').aggregate() .lookup({ from: 'user', localField:'open_id', foreignField:'open_id', as:'user', }) .match({ game_record_id:event.game_record_id }) .replaceRoot({ newRoot: $.mergeObjects([$.arrayElemAt(['$user', 0]), '$$ROOT']) }) .project({ _id:0, open_id:1, user_name:1, identity:1, latitude:1, longitude:1 }) .end() }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。