Column introduction
"Hua Ge You You" is an official Q&A column produced by Cloud Development Cloud Base. The community product manager "Hua Ge" will answer the hot questions of cloud development from different dimensions and analyze common misunderstandings, and help developers use the cloud more efficiently. Development.
Q: How to solve the cloud function time zone problem?
Hua Ge: The time zone in the cloud function is UTC+0, not UTC+8. You can use language time processing related libraries or code packages (such as moment-timezone) to identify UTC time and convert it to +8 zone Beijing time.
Q: Is the cloud function charge based on the set memory or the memory used in actual operation?
Hua Ge: Cloud function fees are calculated according to the function configuration memory and billing duration.
Resource usage = function configuration memory X runtime billing time. User resource usage is calculated by multiplying the configured memory of the function by the billing duration when the function is running. The configured memory is converted to GB units, and the billing duration is converted from milliseconds (ms) to seconds (s). Therefore, the resource The unit of calculation for usage is GBs (GB-seconds). The minimum granularity of the billing duration is 100ms, and it is rounded up if it is less than 100ms. For example, if a function configured as 256MB runs for 1760 ms in a single run and the billing duration is 1800 ms, the resource usage for a single run is (256/1024)*(1800/1000) = 0.45 GBs. For each run of the function, the resource usage is calculated, and the sum is summed up by month as the resource usage of the current month.
Q: For cross-account environment sharing, the caller (small program B) uploads file resources to the sharing party (small program A) and can the resources be called normally?
Hua Ge: Use new wx.cloud.Cloud to create a new instance, and then call the uploadFile interface of the instance. After the resource is successfully uploaded, B is currently unable to access A's resource through fileID. You can use getTempFileURL to change the temporary link first.
Q: For cross-account environment sharing, the caller cannot right-click on the cloud file directory to select the environment and cannot upload cloud functions?
Hua Ge: In the current shared environment, you cannot right-click on cloudfunctions. In addition, because the cloud function has a large authority, the shared environment needs to create and upload cloud functions on the resource side, that is, creating a blank function can be done in the console, but uploading code requires resources Fang uploads in the IDE.
Q: Get the database collection data Collection.get successfully, but returns a null value?
Hua Ge: Reading and writing of the database is restricted by permission control. The default database data permission is "read and write only by the creator". If the business requires all users to read, the developer needs to set the database data permission to "all users can read, only create People can read and write".
Q: The database has no reads or writes. Why does the console resource usage have the number of database operations?
Hua Ge: The operation of the console on the database menu will also produce the number of reads.
Q: How many sets can be created in the database? Single collection size limit?
Hua Ge: In the prepaid mode, the number of database collections depends on the quota scheme of the current environment. 800 collections can be created in the pay-as-you-go mode; the size limit of a single document is 16MB, but it is not recommended to reach the upper limit. The optimal solution is the smaller The better, the table can be split to help improve query efficiency.
Q: How to use database query data limit?
Hua Ge: The default and maximum limit of limit is 20 on the applet side, and the default and maximum limit is 1000 on the cloud function side. It is recommended to obtain more data in batches combined with skip paging.
const params = { // 从集合 data 中随便选点全部 _id:db.command.neq(null)
}
const MAX_LIMIT = 100;
const total = (await db.collection('data').where(params).count()).total;
const batchTimes = Math.ceil(total / MAX_LIMIT)
const tasks = [] for (let i = 0; i < batchTimes; i++) { tasks.push(db.collection('data').where(params).skip(i * MAX_LIMIT).limit(MAX_LIMIT).get())
}
const data = []
if (tasks.length != 0) {
(await Promise.all(tasks)).map(item => {data = data.concat(item.data||[]) })
}
return data
Q: What is the number of simultaneous connections to the cloud development database?
Hua Ge: In the prepaid mode, the number of simultaneous connections to the database depends on the current quota plan. In the pay-as-you-go mode, the number of simultaneous connections to the database is 1,000.
Number of simultaneous database connections: The number of concurrent database requests. If there are 30 database operation requests at the same time, 20 will be executed at the same time, and the remaining 10 will return an out of concurrency error; a database request (regardless of whether it is initiated by the applet or cloud function End-initiated) will consume one connection; each cloud environment has a limit on the number of simultaneous connections and an independent count. If the database query takes an average of 10ms, then one connection can support 100qps (1000ms/10ms=100), and 20 connections can support 2000qps.
Q: How to download cloud storage folders?
Hua Ge: You can directly use the downloadDirectory interface of the SDK to download the folder or use the CLI tool to download.
Q: What are the configuration rules for the storage cache?
Hua Ge: When multiple cache policies are set in the storage configuration, they will overlap each other, and the priority at the bottom of the configuration item list will be higher than the priority at the top.
Hua Ge is polite
What other issues do you want to see in cloud development? Tell us in the comments section! At 12:00 noon on September 3, 2 lucky users will be drawn to present a beautiful gift!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。