const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
const db = cloud.database();
exports.main = async (event, context) => {
const result = await db.collection('goods')
.skip(0)
.limit(10)
.get();
return {
dataList: result?.data,
};
};
上述代码是官方模板中提供的,但运行报错!错误信息如下:
只要去掉result后面的问号(?)即可成功运行。正确的代码如下:
const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
const db = cloud.database();
exports.main = async (event, context) => {
const result = await db.collection('goods')
.skip(0)
.limit(10)
.get();
return {
dataList: result.data,
};
};
nodejs版本多少