当前位置:网站首页>Applet learning notes - Cloud Development
Applet learning notes - Cloud Development
2022-07-20 17:02:00 【Evergrande】
Here's the catalog title
Inquire about
Get a set of data
If you want to get the data of a collection , You can call... On a collection get Method to get , But usually try to avoid getting too much data at one time , Only necessary data should be obtained .
Developers can use limit Method to specify the number of records to get , But the applet side cannot exceed 20 strip , The cloud function end cannot exceed 100 strip .
db.collection('todos').get({
success: function(res) {
// res.data Is a data that contains all records in the collection that have permission to access , No more than 20 strip
console.log(res.data)
}
})
Get a record of data
Let's take a look at how to get a recorded data , Suppose we have a ID by todo-identifiant-aleatoire In collection todos Record on , Then we can call... Through the reference in the record get Method to get the data of the to-do :
db.collection('todos').doc('todo-identifiant-aleatoire').get().then(res => {
// res.data Data containing the record
console.log(res.data)
})
Get the data of multiple records
where Method receives an object parameter , Each field in the object and its value constitute a matching condition to be met , The relationship between the fields is “ And ” The relationship between , That is, these matching conditions must be met at the same time , In this case , Is to find todos Collection _openid be equal to user-open-id And done be equal to false The record of . We can also specify the value matching a nested field in the query criteria , For example, find your yellow to-do list :
db.collection('todos').where({
_openid: 'user-open-id',
style: {
color: 'yellow'
}
})
.get({
success: function(res) {
console.log(res.data)
}
})
What if the query is greater than or less than , use db.command Of .gt function
const _=db.command
findData(){
db.collection('douban')
.where({
price: _.gt(10)
})
.field({
name: true,
price: true,
})
.orderBy('price', 'desc') //desc Descending order
// .skip(1)
// .limit(10)
.get()
.then(res => {
console.log(res.data)
})
.catch(err=>{
console.log(err)
})
},
where Only conditions can be executed “ And ” operation , If the condition is or operation :
Single field or operation
Field value “ or ” Operation refers to specifying a field value as one of multiple values .
If the screening progress is greater than 80 Or less than 20 Of todo:
Stream writing :
const _ = db.command
db.collection('todo').where({
progress: _.gt(80).or(_.lt(20))
})
Preposition :
const _ = db.command
db.collection('todo').where({
progress: _.or(_.gt(80), _.lt(20))
})
Pre writing can also receive an array :
const _ = db.command
db.collection('todo').where({
progress: _.or([_.gt(80), _.lt(20)])
})
Cross field or operation
Cross field “ or ” Operation refers to condition “ or ”, It is equivalent to that multiple where sentence , Just meet one of them .
If the screening progress is greater than 80 Or marked as completed todo:
const _ = db.command
db.collection(‘todo’).where(_.or([
{
progress: _.gt(80)
},
{
done: true
}
]))
Other conditions
in,eq,neq,nin,exsit,mod
Get cell phone number
Use 2.7.0 Or above , If the app has cloud development , In the return value of the open data interface, you can use cloudID Field get ( And encryptedData At the same level ),cloudID Valid for five minutes .
For example button Of getphonenumber You can get the mobile phone number in the callback function of cloudIDWhen calling cloud function , The incoming data Parameters , If the value of the top-level field is through wx.cloud.CloudID Tectonic CloudID, When the cloud function is called , The values of these fields are replaced with cloudID The corresponding open data , One call can replace at most 5 individual CloudID.
//button Of getphonenumber Callback function :
getPhoneNumber(e) {
cloudid=e.detail.cloudID
wx.cloud.callFunction({
name: 'getcontext',
data: {
phoneNumber: wx.cloud.CloudID(cloudid)
}
}).then(res => {
console.log(res.result.event.phoneNumber.data.phoneNumber) // cell-phone number
})
}
Cloud functions :getcontext:
// Return open data
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
}
}
The second way :
<button open-type="getPhoneNumber" bindgetphonenumber="handleGetPhoneNumber"> Mobile phone number Authentication </button>
js:
handleGetPhoneNumber(e) {
let cloudID = e.detail.cloudID // Open data ID
if (!cloudID) {
app.showToast(' User not authorized ')
return
}
// Call the cloud function to get the mobile phone number
wx.cloud.callFunction({
name: 'getphone',
data: {
weRunData: wx.cloud.CloudID(e.detail.cloudID),
}
})
.then(res => {
console.log(' cell-phone number ', res)
})
.catch(err => {
console.log(' cell-phone number err', err)
})
}
Cloud functions getphone.js:
exports.main = async (event, context) => {
// Get basic information
var moblie = event.weRunData.data.phoneNumber;
return moblie
};
边栏推荐
- ProSci 15-PGDH重组蛋白说明书
- Apifox quick survey
- Human cell research: prosci LAG-3 recombinant protein scheme
- 小程序的FLEX的垂直布局弹性压缩
- Oom memory overflow is a classic that we have to watch in actual combat
- @Data注解的使用(代替实体类中的get和set方法)
- Kylin opens the dashboard monitoring panel
- Prosci 15 PGDH recombinant protein specification
- Worthington core enzyme -- application field of trypsin
- viewport、布局视口、视觉视口、理想视口 深入理解
猜你喜欢
WebService初识(生成jar包,调用远程服务中的方法)
C语言的学习之路(一)——初识C语言
Zero copy is really important!!!
Redis 如何分析慢查询操作?
小程序毕设作品之微信预约订座小程序毕业设计(3)后台功能
Interactive drawing of complex tables from the perspective of app
A novel network training approach for open set image recognition
小程序毕设作品之微信预约订座小程序毕业设计(4)开题报告
ID生成器实现方式的优缺点比较以及最优的ID生成器原理剖析
小程序毕设作品之微信预约订座小程序毕业设计(2)小程序功能
随机推荐
Worthington肌动蛋白——分子特征及相关应用
双亲委派模型和破坏性双亲委派模型详解
PHP报错:Classes\\PHPExcel\\Cell.php Line(594) Invalid cell coordinate ESIGN1
Human cell research: prosci LAG-3 recombinant protein scheme
为什么重写equals方法时必须重写hashCode方法
C# 9.0 正式版所有新特性概述
Oom Memory overflow a classic That Must See in Real Games
Prosci human cell line I imprinting human immune research
photoshop印章效果制作
Conservative Novelty Synthesizing Network forMalware Recognition in an Open-Set Scenario
Worthington core enzyme -- application field of trypsin
LabView---信号发生器
OOM內存溢出實戰不得不看的經典
Application of Worthington core collagen protease & Analysis of references
零拷贝真的很重要!!!
力扣——1046. 最后一块石头的重量
Addressing Visual Search in Open and Closed Set Settings
OpenGL ES之实现实时音频的可视化
小程序毕设作品之微信小程序点餐系统毕业设计(2)小程序功能
crontab定时任务通过脚本执行jar过程中,遇到jar包执行无效的坑