- 如何在云函数中实现批量插入数据?
[代码]db.collection([代码][代码]'test'[代码][代码])[代码] [代码] [代码][代码].add({[代码][代码] [代码][代码]data: [[代码][代码] [代码][代码]{[代码][代码] [代码][代码]_id: [代码][代码]'apple-1'[代码][代码],[代码][代码] [代码][代码]name: [代码][代码]'apple'[代码][代码],[代码][代码] [代码][代码]category: [代码][代码]'fruit'[代码][代码],[代码][代码] [代码][代码]price: 10,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]_id: [代码][代码]'orange-1'[代码][代码],[代码][代码] [代码][代码]name: [代码][代码]'orange'[代码][代码],[代码][代码] [代码][代码]category: [代码][代码]'fruit'[代码][代码],[代码][代码] [代码][代码]price: 15,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]_id: [代码][代码]'watermelon-1'[代码][代码],[代码][代码] [代码][代码]name: [代码][代码]'watermelon'[代码][代码],[代码][代码] [代码][代码]category: [代码][代码]'fruit'[代码][代码],[代码][代码] [代码][代码]price: 20,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]_id: [代码][代码]'yaourt-1'[代码][代码],[代码][代码] [代码][代码]name: [代码][代码]'yaourt'[代码][代码],[代码][代码] [代码][代码]category: [代码][代码]'dairy'[代码][代码],[代码][代码] [代码][代码]price: 8,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]_id: [代码][代码]'milk-1'[代码][代码],[代码][代码] [代码][代码]name: [代码][代码]'milk'[代码][代码],[代码][代码] [代码][代码]category: [代码][代码]'dairy'[代码][代码],[代码][代码] [代码][代码]price: 12,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]_id: [代码][代码]'chocolate-1'[代码][代码],[代码][代码] [代码][代码]name: [代码][代码]'Lindt chocolate'[代码][代码],[代码][代码] [代码][代码]category: [代码][代码]'chocolate'[代码][代码],[代码][代码] [代码][代码]price: 16,[代码][代码] [代码][代码]},[代码][代码] [代码][代码]][代码][代码] [代码][代码]})[代码] 我在云开发后台操作这段批量插入的代码是可以正常执行的, 但写在云函数里面却报了以下错误 parameter.data should be object instead of array 请问云函数里面可以做批量插入吗,要怎么写才对呢?
2019-11-25 - 在云函数中操作数据库时, 使用_.gt为何会报错?
[代码]function[代码] [代码]resetLottery(){[代码][代码] [代码][代码]console.log([代码][代码]"resetLottery start"[代码][代码])[代码][代码] [代码][代码]//清空ticket表[代码][代码] [代码][代码]cloud.database().collection([代码][代码]'ticket'[代码][代码])[代码][代码] [代码][代码].where({[代码][代码] [代码][代码]time: _.gt(10)[代码][代码] [代码][代码]})[代码][代码] [代码][代码].get()[代码] [代码] [代码][代码].then(res=>{[代码][代码] [代码][代码]console.log([代码][代码]"resetLottery"[代码][代码],res)[代码][代码] [代码][代码]})[代码][代码] [代码][代码].[代码][代码]catch[代码][代码](err=>{[代码][代码] [代码][代码]console.log([代码][代码]"resetLottery"[代码][代码], err)[代码][代码] [代码][代码]})[代码] [代码]}[代码] 代码是这样的,一样的_.gt在云开发数控制的可以正常使用,但在云函数调用时出现了如下报错 getConfig fail ReferenceError: _ is not defined 是我哪里写得不对吗?求解答
2019-11-25