当前位置:网站首页>Wechat applet 6 cloud development cloud database
Wechat applet 6 cloud development cloud database
2022-07-19 15:12:00 【k55】
Wechat applet 1- The basics of applets , Installation and use of development tools
Wechat applet 2-WXSS,WXS
Wechat applet 3- Applet lifecycle and components
Wechat applet 4- Applet api
Wechat applet 5- Real machine test
1. Development of cloud
1). What is cloud development
Wechat cloud development is a professional applet development service launched by wechat team and Tencent cloud .
Developers can use cloud development to quickly develop small programs 、 Little games 、 The official account page, etc , And the original ability to open wechat .
Developers don't have to build servers , You can directly use the API Business development
2). Advantages of cloud development
2. Using cloud development
1). Create an applet , Choose cloud development
2). Open Cloud Development , Create an environment
Each environment is isolated from each other , Have a unique environment ID, Contains independent database instances 、 Storage space 、 Cloud function configuration and other resources
3. Cloud database
Cloud development provides a JSON database , seeing the name of a thing one thinks of its function , Every record in the database is a JSON Formatted objects . A database can have multiple collections ( It's equivalent to a table in relational data ), A collection can be seen as a JSON Array , Every object in the array is a record , The format of the record is JSON object
1). Create a collection in the cloud database
Set up id Self increasing
Modify the permissions of the set , Give read and write permission , Otherwise, the permission exception will be reported :database permission denied
2). Cloud database - newly added
(1). Insert data in the cloud console
Query the insert template on the cloud console
db.collection('user')
.add({
data: [
{
_id: '1',
name: 'yw1',
sex: ' male ',
price: 10,
},
{
_id: '2',
name: 'yw2',
sex: ' male ',
price: 15,
},
{
_id: '3',
name: 'yw3',
sex: ' Woman ',
price: 20,
},
]
})
Execute insert statement
View set
(2). Insert data through code
add(){
// Get a reference to the cloud database
const db = wx.cloud.database()
db.collection("user").add({
data: {
//id Auto increment is set , Can not pass , Will automatically give a value
// _id:"5",
name: "yw5",
age: 23,
sex:" Woman ",
}
}).then(res=>{
console.log(res)
console.log(res._id)
})
}
3). Cloud database - Inquire about
(1). Query data through the cloud development console
db.collection('user')
.where({
name: 'yw1'
})
.field({
name: true,
age: true,
})
.get()
(2). Query data through code
// Get a reference to the cloud database
const db = wx.cloud.database()
db.collection('user').where({
name: 'yw1',
}).get({
success: function(res) {
console.log(res)
}
})
}
4). Cloud database - Delete
(1). Delete through the cloud development console
doc It's filled in with id
db.collection('user').doc('1')
.remove()
(2). Delete by code
// Get a reference to the cloud database
const db = wx.cloud.database()
db.collection('user').where({
name: 'yw2',
}).remove()
5). Cloud database - to update
(1). Update through the cloud development console
db.collection('user')
.where({
name: 'yw3'
})
.update({
data: {
age:56,
sex:' male '
}
})
(2). Modify... By code
const db = wx.cloud.database()
db.collection('user').where({
name: 'yw3',
}).update({
data: {
age:58,
sex:' male '
}
}).then(res=>{
console.log(res)
console.log(res._id)
})
边栏推荐
- [flask introduction series] request hook and context
- 2020 ICPC Asia East Continent Final G. Prof. Pang‘s sequence 线段树/扫描线
- session management
- UVA - 12096 The SetStack Computer
- 现场可程式化逻辑闸阵列 FPGA
- Behind the high salary of programmers' operation and maintenance
- A - Play on Words
- P1004 [NOIP2000 提高组] 方格取数
- 揭开服务网格~Istio Service Mesh神秘的面纱
- csrf防护机制
猜你喜欢
随机推荐
SBOM(Software Bill of Materials,软件物料清单)
009 execution sequence of SQL statement of interview questions
国科大.深度学习.期末复习知识点总结笔记
微信小程序9-发布代码
微信小程序合集
FPGA (VGA Protocol Implementation)
P1004 [noip2000 improvement group] grid access
Read the paper: temporary graph networks for deep learning on dynamic graphs
TDesign compositionapi refactoring path
ICML2022 | 幾何多模態對比錶示學習
2021.07.13【B站】是这样崩的
Several points to be analyzed in the domestic fpga/dsp/zynq scheme
ORA-08103
2、MYSQL介绍
Summary of the third week of summer vacation
A - Play on Words
CSRF protection mechanism
模块1 作业
解决jupyter控制台出现中文乱码的问题
长安链学习研究-存储分析wal机制