index.wxml
<view>
<button bindtap='insertData'>插入数据</button>
<button bindtap='queryData'>请求数据</button>
</view>
index.js
// 单击“插入数据”按钮调用该函数
insertData: function () {
const db = wx.cloud.database({});
const cont = db.collection('todos');
cont.add({
data: {
description: "向云数据库插入一条数据",
due: new Date('2018-12-25'),
tags: [
"cloud",
"database"
],
},
success: function (res) {
console.log(res._id)
}
});
},
// 单击“请求数据”按钮执行该函数
queryData: function () {
const db = wx.cloud.database({});
const cont = db.collection('todos');
cont.doc("XCIGn8DR1TiNF-Pt").get({
success: function (res) {
console.log(res.data)
}
})
},
创建todos集合