当前位置:网站首页>The applet reads more than 20 data, and the cloud function reads more than 100 restrictions
The applet reads more than 20 data, and the cloud function reads more than 100 restrictions
2022-06-24 08:08:00 【Programming pebbles】
Students who have seen the basic course of stone Geyun development must know , Request data directly in the applet, and you can only return at most 20 Data , The requested data in the cloud function can only return at most 100 Data , If you want to break through this limit , The best way is to do paging , Of course, I also teach you in Cloud Development Foundation . But there is a need to limit , What if we want to get all the data stored in the database at one time , For example, there are... In the database 1000 Data , We want to get it all at once , How do you do that ???
Today, let's teach you how to return up to... Each time through the cloud function 100 Restrictions on .
One , Cloud function breakthrough 100 Restrictions on
As shown in the figure above , my num There are 103 Data , If you follow the previous pagination idea , It's two requests , First request 1-100 strip , Second request 101-103 strip . So we can get it 103 Data , But it takes two requests , How do we do it , Only one request can get this information 103 Data .
1-1, breakthrough 100 Principle of bar
In fact, the principle is the same as our paging principle , It's just that we use for Loop multiple requests , Then combine the multiple requests together , Then return the combined data all at once . In this way, all data is obtained through one request .
1-2, Code implementation
The code here is written in the cloud function , I'll write down the operation steps in the notes .
As shown in the figure above , We only need to go through three steps , You can get everything 103 Bar data .
So we can pass a request , Got all the data . Does it feel very simple . Here the code is posted to everyone .
// Cloud function entry file
const cloud = require('wx-server-sdk')
// Cloud development environment initialization
cloud.init({env: cloud.DYNAMIC_CURRENT_ENV})
exports.main = async (event, context) => {
const db = cloud.database()
// 1, Total number of acquired data
let count = await db.collection('num').count()
count = count.total
// 2, adopt for Loop multiple requests , And put the data requested many times into an array
let all = []
for (let i = 0; i < count; i += 100) { // Set the amount of data obtained each time
let list = await db.collection('num').skip(i).get()
all = all.concat(list.data);
}
// 3, Return all the assembled data at one time
return all;
}1-3, matters needing attention
The data returned by a cloud function cannot exceed 1M, If you need more than 1M, You need to use the data query on the applet side 20 strip 20 The of bars are combined . So if you want to return a lot of data at once , You can consider requesting the database directly in the applet , Then I do 20 strip 20 Assembly of bar .
I will also teach you how to assemble in small programs .
Two , Applet directly requests database breakthrough 20 strip
2-1, Turn on async and await
We won't talk about the principle here , It's as like as two peas. , But in small programs await You need to do the following simple operations , You can also read another article of mine .
It seems that the latest version of the applet developer tool supports async and await The method , It seems that it's OK not to check enhanced compilation . But for safety's sake , It's better to check enhanced compilation .
2-2, Authority modification
Get the data in the database directly from the applet , Remember to change the permissions of the collection
2-3, Code implementation
Careful students can certainly see it , The above code is basically as like as two peas in our cloud function .
Here we have perfectly broken through the limitation of small programs , Return any number of data we want .
Later, we will summarize more small program knowledge points for you , Welcome to your attention , Welcome to leave a message .
边栏推荐
- auto使用示例
- L1-019 who goes first (15 points)
- Chapitre 2: dessiner une fenêtre
- [008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
- OpenGauss数据库在 CentOS 上的实践,配置篇
- 热赛道上的冷思考:乘数效应才是东数西算的根本要求
- Application of JDBC in performance test
- 第 2 篇:繪制一個窗口
- ImportError: cannot import name ‘process_pdf‘ from ‘pdfminer.pdfinterp‘错误完全解决
- Thread support
猜你喜欢

研究生英语期末考试复习
![[run the script framework in Django and store the data in the database]](/img/6b/052679e5468e5a90be5c4339183f43.png)
[run the script framework in Django and store the data in the database]

Practice of opengauss database on CentOS, configuration

Hongmeng OS development III

首次曝光 唯一全域最高等级背后的阿里云云原生安全全景图

Signature analysis of app x-zse-96 in a Q & a community

The monthly salary of two years after graduation is 36K. It's not difficult to say

Hilbert Huang Transform

GraphMAE----论文快速阅读

一文理解同步FIFO
随机推荐
Svn actual measurement common operation record operation
The two most frequently asked locks in the interview
Graphmae ---- quick reading of papers
Simple summary of lighting usage
ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
某问答社区App x-zse-96签名分析
热赛道上的冷思考:乘数效应才是东数西算的根本要求
Specify IP when calling feign interface
Standing at the center of the storm: how to change the engine of Tencent
Atguigu---16-custom instruction
What is the lifecycle of automated testing?
Sql语句内运算问题
These dependencies were not found: * core JS / modules / es6 array. Fill in XXX
单片机STM32F103RB,BLDC直流电机控制器设计,原理图、源码和电路方案
Coordinate transformation of graphic technology
Leetcode 174 Dungeon games (June 23, 2022)
Shader common functions
Thread considerations
Model effect optimization, try a variety of cross validation methods (system operation)
Introduction to software engineering - Chapter 2 - feasibility study