# What is the difference between uniCloud and WeChat MiniApp cloud development and Alipay MiniApp cloud development?

WeChat, Alipay, and Baidu's MiniApp all provide cloud development. But they only support their own MiniApp and cannot be used on other terminals.

uniCloud uses the same infrastructure platform as WeChat MiniApp MiniApp Development and Alipay MiniApp Program Cloud Development. Behind WeChat Mini Program Cloud Development is the TCB team of Tencent Cloud, and behind Alipay MiniApp Cloud Development is the Alibaba Mini MiniApp Cloud Team. uniCloud is a cross-device cloud development solution provided by DCloud, Alibaba MiniApp Cloud team, and Tencent Cloud's TCB team, who directly carry out in-depth cooperation and perform secondary packaging on the basis of their underlying resources.

In short, uniCloud is as stable and robust as WeChat MiniApp Cloud Development and Alipay MiniApp Cloud Development, but has more advantages:

  • Cross-platform. Regardless of whether you choose Ali or Tencent's serverless in uniCloud, you can use it across the entire uni-app. From pc to h5, from Android to iOS, and various MiniApp and QuickApp, more than a dozen platforms are fully supported
  • uniCloud提供了clientDB神器,减少90%的服务器开发工作量,且保障数据安全。详见
  • uniCloud提供了uni-iduniPay等重要框架,大幅减少开发者的相应功能开发量。
  • uniCloud provides uni-starter, which greatly reduces the workload of client development.
  • uniCloud provides uniCloud admin, which greatly reduces the development workload on the management side.
  • uniCloud provides schema2code. You only need to compile the database schema file, and the data list, pagination, search, details view, modification, and deletion on the client side and management side can automatically generate a complete set of codes.
  • Easier to learn. uniCloud provides JQL query language, which is simpler and easier to master than the query syntax of SQL and MongoDB, especially the join table query is very simple. See details
  • Improved toolchain. Front-end uni-app, cloud uniCloud, and ide-side HBuilderX are closely matched with each other to create an excellent closed-loop development experience
  • Richer ecology. There are a lot of ready-made wheels and resources in the plug-in market see details

If you have used WeChat MiniApp cloud development and want to learn more about the comparison and differences or how to migrate from WeChat MiniApp cloud to uniCloud, see

# Is uniCloud stable? Will DCloud server abnormality affect my online business?

uniCloud is a cloud service product jointly launched by DCloud and mature cloud vendors such as Alibaba Cloud and Tencent Cloud. Alibaba Cloud and Tencent Cloud provide basic cloud resources, and DCloud provides API design, front-end framework, IDE tool support, management console, and plug-ins For services such as ecology, developers' cloud functions are directly hosted on the serverless platforms of service providers such as Alibaba Cloud.

When the application on the user terminal is running, it is directly connected to the serverless platform of the cloud service provider without going through the DCloud server. Developers do not need to worry about the problem of affecting their business due to the load of the DCloud server.


# What is the difference between Cloud Functions and traditional Node.js development?

Cloud Functions is equivalent to Node.js + Serverless + DCloud improvements.

  • Traditional Node.js development needs to purchase a server, install the Node.js environment, and deploy pm2 and other daemon processes; cloud functions do not need to consider the server environment, only need to concentrate on implementing business code, and then upload the cloud function with one click, and the cloud service provider is responsible for the cloud Preparation of the function execution environment.
  • In the traditional Node.js development mode, developers need to monitor server parameters, such as hard disk usage, to avoid business interruption caused by excessive server load; in the cloud function mode, developers do not need to care about the host environment where the cloud function runs, and the cloud vendor will implement the service Provisioning and hardware monitoring.
  • When the number of users is large, traditional Node.js development needs to consider purchasing more servers and achieving load balancing; in the cloud function mode, the cloud service provider automatically expands elastically, and developers do not need to worry about the server being unable to bear the pressure.
  • In the traditional Node.js development mode, security protection needs to be considered, such as DDos attacks; in the cloud function mode, the API gateway of the cloud vendor will do interception protection, developers do not need to care, and can save high-defense IP and other costs

To sum up, even if the front-end students can write Node.js code proficiently, they still lack experience in DB optimization, elastic expansion, attack protection, disaster recovery processing, etc., but uniCloud encapsulates these and truly achieves Only focus on business implementation, and entrust cloud vendors with other services.

In addition, in terms of Node.js code implementation, the host environment (which can be simply understood as a virtual machine or server hardware) for each execution of a cloud function may be the same or different. Therefore, in traditional Node.js development, some information is stored locally Hard disk or memory solutions are no longer suitable, and it is recommended to use cloud database or cloud storage solutions instead.

Of course, there is the most important point. In uniCloud, it is recommended to use clientDB for a large number of businesses. Too many cloud functions cannot be written in one application.

# uniCloud only supports uni-app, how to develop web interface?

uni-app can develop web interface, see: uni-app widescreen adaptation guide

If you need admin for PC, uniCloud provides uniCloud admin

# Can I access cloud functions or cloud databases through http url?

  • Scenario 1: For example, WeChat payment on the app side needs to be configured with a server callback address. In this case, an HTTP URL is required.
  • Scenario 2: For a system not developed by uni-app, if you want to connect to uniCloud and read data, you also need to access it through HTTP URL.

uniCloud provides cloud function URLization to meet the above requirements. See details

# WeChat cloud development supports the client to directly operate the database, does uniCloud support it?

uniCloud provides a better front-end operation database solution than WeChat cloud development, see: clientDB

# Cloud development is a combination of nodejs+improved version of MongoDB. How does it compare to the traditional combination of php+mysql?

The performance of nodejs is better than php, and the performance of MongoDB is better than mysql.

For the front end, a json-like document database such as MongoDB is easier to use and has higher flexibility. The method of operating MongoDB still uses js.

MongoDB is very flexible and can add fields to tables with large amounts of data at will. However, once the amount of data in mysql table becomes large, every time a field is added, the size and performance of the database will be negatively affected.

The fields of MongoDB can be nested, and it is very convenient to express tree-type data, and it can be expanded as you like.

For developers who want to increase data redundancy to improve performance, nosql databases are a powerful tool.

Of course, for developers who prefer traditional databases, the database table structure can still be designed in the traditional way.

MongoDB is much more powerful than mysql. SQL is too simple. A SQL statement is actually a string, and complex logic cannot be written.

And MongoDB has a lot of js APIs and various aggregation operators, which are programmable, rather than expressed by a string of SQL statements.

For example, there are 4 fields in the product data table: views, favorites, purchases, and reviews. It is necessary to generate a list of recent popular products, each of which has a weight of 25% in each of the four fields, and sort them after weighting. This requirement cannot be directly realized by sql. In MongoDB, a query can directly return the sorted results.

The fuzzy query of SQL is also very weak, like only before and after %, so many developers have to use third-party databases such as ElastciSearch. Although later versions of mysql also support limited regularization. But MongoDB's regular query is still more powerful than developers expected.

Although MongoDB is powerful, it is not easy to use, especially the aggregation operation is very complicated to write.

uniCloud improves on the basis of MongoDB and further provides DB Schema and JQL.

DB Schema is a json file that can describe data, agree on field value ranges, control operation permissions, and describe the relationship between fields, making database management more efficient and greatly reducing the workload of code development on the server side. See details

JQL is a set of methods to operate the uniCloud database, which is more in line with the habits of js developers, and greatly reduces the learning cost and code volume. For example, joint table query and tree query have become very simple. Such as tree query is a function that only Oracle has in the past. JQL documentation see details

In the past, DCloud officially promoted Alibaba Cloud and Tencent Cloud to provide serverless mysql. However, after in-depth research and improvement of MongoDB, DCloud has given up the difficult-to-use mysql. It is recommended that developers learn about uniCloud's cloud database, which is more powerful and convenient to use.

# 支持websocket吗?



  1. uni-push2.0, full-end support (APP, H5, each end MiniApp) is a free websocket service when the application is online, detailed document: https://uniapp.dcloud.io/unipush-v2.html
  2. If it is an IM requirement, there is a cloud-integrated, full-platform, free, open-source instant messaging system developed by DCloud based on uni-push2.0. For details, check: https://uniapp.dcloud.net.cn /uniCloud/uni-im.html

# How to import data from old database?

  • Method 1: You can use db_init.json in HBuilderX to create cloud databases and insert table content in batches, [see details](https://uniapp.dcloud.io/uniCloud/cf-database?id=%e4%bd% bf%e7%94%a8db_initjson%e5%88%9d%e5%a7%8b%e5%8c%96%e9%a1%b9%e7%9b%ae%e6%95%b0%e6%8d%ae% e5%ba%93)
  • Method 2: Alibaba Cloud supports direct import and export of data on the uniCloud web console interface
  • Method 3: In the cloud function, use the nodejs standard writing method to connect to the old database, such as using the mysql plugin to read the data, Then write to the cloud database in batches
  • Method 4: URLize a cloud function, read the old database in other languages, submit it to the cloud function through http, and the cloud function will store the received data into the cloud database

# What happens when the cloud function access is fast and sometimes slow?

If the resources corresponding to cloud functions are not used for a long time, they will be released from memory by Alibaba Cloud or Tencent Cloud Platform. Once released, there will be a cold start process when starting the cloud function.

The performance is: after a long time without use, the first use will be slower, and then the second visit immediately will be very fast, with a millisecond response.

The cold start speed generally does not exceed 1.5 seconds. If it exceeds 1.5 seconds, it should be a problem with the cloud function or the network.

In terms of resource recovery policy, Alibaba Cloud will be recycled if there is no second visit to the cloud function within 15 minutes. Tencent Cloud is half an hour.

The two cloud vendors are still optimizing this problem. At present, if developers care about this issue, the suggestions for developers are:

  1. Using clientDB can reduce the probability of encountering cold start problems
  2. Cloud functions that are not frequently accessed are merged into high-frequency cloud functions. Some developers use a pure single-page method to write cloud functions, that is, implement all the background logic of the entire application through routing processing in one cloud function. Refer to Plugin
  3. For non-frequently accessed cloud functions, you can continue to run them through scheduled tasks (note that Tencent Cloud can use this method to completely avoid cold start, and Alibaba Cloud's scheduled task minimum period is greater than the resource recovery period)
  4. To configure the single-instance multi-concurrency of cloud functions, please refer to: Single-instance multi-concurrency

# uniCloud access speed is not as good as traditional servers?

A developer installs php or java on a single computer and connects to mysql on the same computer. Then compare the speed with uniCloud, and think that uniCloud is slow. The following differences need to be clarified here:

  • Cause 1. Cold start. For detailed analysis, see the previous question

  • Reason 2. Code and database are not on the same server Install php or java on a single machine, and install the database at the same time, the access speed is really fast. But when using a cloud database, that is, the database is a separate server, and the running code is not on the same server, it will cause a slight delay. But the databases for commercial applications must all be independent servers.

  • Reason 3. Interceptor Requests for back-end development generally have routing management frameworks or interceptors, and each request must be intercepted and permissions verified. Using such frameworks will definitely increase the time consumption.

This is the case with clientDB, because clientDB has a permission verification system inside, and the verification of certain permissions also requires database queries.

Therefore, although the speed of clientDB is slower, in fact, after developers write the framework for routing interception and authority management, the speed will also decrease.

From uni-id 3.0 onwards, the user's role permissions are cached in the token, and the library is no longer checked. The speed of clientDB is about 100 milliseconds faster than before. If you have not upgraded, please upgrade as soon as possible. At the same time, note that if you use uniCloud admin, you must also upgrade it. If you have written relevant business logic in cloud functions, please be sure to read the upgrade notes.

  • Reason 4. Database index

The index of the query table must be correctly configured. It is recommended to add an index to the fields that need to be queried in where, otherwise the query will be very slow.

But be careful not to have too many indexes, otherwise it will slow down when adding, deleting, and modifying data. Accuracy is very important. It is recommended to read Index Document in detail

# When releasing H5, you have to find a server to deploy the front-end webpage. Can you not find a server by yourself?

uniCloud supports front-end web hosting, and it is completely free when you choose Alibaba Cloud as a cloud provider!

  • If you already have a registered domain name, just resolve it directly;
  • If you want to register a new domain name, the filing process is slightly different from traditional cloud hosting, involving a problem that uniCloud does not have a fixed IP. At this time, you can go to buy the filing service of peanut shells; you can also temporarily buy a short-term fixed IP and go through the fixed IP filing. Here are [Experience Posts] shared by developers (https://ask.dcloud.net.cn/article/38116)

If it is because WeChat js sdk and other services require the configuration of a fixed ip whitelist, then Tencent Cloud’s charging space already supports fixed ip, see details

uniCloud's cloud database itself is a document database, which can be searched in full text.

Regular expressions can be passed in when querying data. Compared with SQL's like, which only has % before and after, regular expressions are much more powerful. For details, please refer to Regular Expression Query

Of course, if you need to configure additional third-party databases such as ElastciSearch, you can also find a server to install these services yourself, synchronize data, and synchronize the data that needs to be searched.

# How to use formdata in uniCloud

nodejs itself does not support formdata, but it can be supported by manually assembling formdata, reference

Example of using with uniCloud.httpclient.request

const FormData = require('form-data');
let form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', new Buffer(10));

form.append('img', new Buffer(10), {
  filename: `${Date.now()}.png`,
  contentType: 'image/png'

  content: form.getBuffer(),
  headers: form.getHeaders()

# What are the major cases of Tencent and Ali's serverless?

  • Wechat MiniApp cloud development, already has 500,000 developers, including many of Tencent's own big daily life applications are built on Tencent Cloud serverless, such as WeChat life payment, ride code, WeChat reading, Tencent news, Tencent photo album, etc.
  • On Double 11 in 2019, part of Ali's business has been migrated to serverless. The Alipay MiniApp also provides cloud development functions.

# How to control the number of cloud functions? Can cloud functions be sorted by multi-level directories

There is no need to control the quantity, and the limit will not be broken in actual development.

Because the framework will be used in actual development instead of developing cloud functions one by one.

  1. Use clientDB. This method is to directly operate the database on the front end, and at this time, no cloud function needs to be written. The development efficiency far exceeds the traditional development mode. Including its supporting action cloud function does not occupy the number of cloud functions.
  2. Use uni-cloud-router single-route cloud function framework, this method has only one cloud function, and all interfaces are this Different parameters of the cloud function, it has a unified routing management.


  • uni-id会有一个云对象(uni-id-co)或老版的云函数(uni-id-cf),这是必备的一个云函数
  • If you use uni statistics, app uni-upgrade-center, uni publishing platform, uniPush2, uni-search hot search word statistics running batch,these will automatically with cloud function

The above are the cloud functions carried by several commonly used frameworks recommended by the government, and in the developer’s own code, most of the business is developed using clientDB, without writing cloud functions, or writing supporting action cloud functions without occupying cloud functions Quantity; if you still need to write some cloud functions yourself, add uni-cloud-router, and use this single-router cloud function to meet the remaining needs; in addition, if you need to run batch data, you can add another cloud function. So in any case, 48 cloud functions are not enough.

Each cloud function of uniCloud is an independent process, and there is no multi-level directory concept at the cloud function level.

There can be subdirectories under each cloud function, but they all belong to a part of this cloud function, not another cloud function.

The single-router cloud function framework is not only the official uni-cloud-router, there are many similar frameworks in the plug-in market: [see for details](https://ext.dcloud.net.cn/search?q=%E8%B7%AF %E7%94%B1&cat1=7&orderBy=TotalDownload)

# What should I do if the access of users from Hong Kong, Macao, Taiwan and overseas is relatively slow


  1. Refer to the Alibaba Cloud Global Acceleration document, activate the service and accelerate own domain name
  2. CNAME the above domain name to api.next.bspapp.com
  3. Initialize uniCloud by yourself pass in the endpoint parameter, whose value is your own domain name for global acceleration

# What should I do if Tencent Cloud prompts that the current real-name subject already has three accounts

When opening Tencent Cloud service space, the real-name authentication prompts that the real-name subject already has three accounts. This is often because the developer has accidentally opened multiple free MiniApp clouds in the WeChat MiniApp development tool. At this time, you can refer to the following process to cancel the unused accounts. :

  1. Open the Tencent Cloud Forgot Account page
  2. Select the method of retrieving the account as real-name information
  3. After the operation is completed, you can see all Tencent Cloud accounts corresponding to your real name information
  4. Choose an unused account to log in and log out. Refer to the document: Cancel Tencent Cloud Account

At the same time, if you pay to purchase Tencent Cloud service space, each account can have a maximum of 50 Tencent Cloud service spaces (note that only one of them enjoys a free quota).

# Simple way to prevent oversold under high concurrency

uniCloud Alibaba Cloud now supports redis. To enable and use redis, please refer to: Redis activation and use. md?id=snap-over-sell) (recommended). The following method is not flexible for scenarios without redis (not recommended)

When the concurrency is high, many users read and write a piece of data at the same time, which can easily cause data confusion, which is manifested in scenarios such as flash sales and panic buying, which are oversold. Taking seckill as an example, developers can start from deducting inventory to greatly limit overselling. The following is a simple example (note that the following code does not use transactions)

// cloud function
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async function(event){
  const transaction = await db.startTransaction()
  // other business logic...
  // Inventory minus one
  const reduceRes = await db.collection('goods').where({
    _id: 'goods_id', // 商品ID
    stock: dbCmd.gt(1) // 限制库存大于1的才允许扣除库存
    stock: dbCmd.inc(-1)
  if(reduceRes.updated === 0) { // 如果没成功更新库存就认为下单失败
    await transaction.rollback()
    return {
      code: 1001,
      message: '下单失败'

# Cloud storage, database has not been used a few times

About cloud storage: The number of reads and writes here is not necessarily for files: including: uploading files, modifying policies, modifying ACLs, modifying CORS, etc., will be considered as COS writes. When the environment is initialized, many initialization operations will be performed, and configuration information such as policy/acl/cors will be written. Every time the user operates to modify the security domain name, modify the static domain name, etc., it will also trigger the writing of CORS.

About the database: Developers accessing the database through the uniCloud web console will also increase a small number of reads and writes

# Deploy the website to the front-end web hosting and report "The requested file was not found on this server."

  • When deploying the uni-app project in history mode, if the configuration of the front-end web page hosting is not modified, the above error will be encountered when directly accessing the sub-page. For how to configure, please refer to Deploy uni-app project

# Use Tencent Cloud Report without logging into Cloudbase

Tencent Cloud will store some information in the local storage, please do not use interfaces such as clearStorage to directly delete the storage during application use.

# Alibaba Cloud front-end web hosting domain name error guide

  1. Error message: This domain name has already been added and cannot be added again

Front-end web hosting will conflict with other CDN services on Alibaba Cloud (including but not limited to CDN). If you want to bind to front-end web hosting, please first disassociate this domain name from other services.

  1. Error message: The root domain of your domain is reserved by another account

Currently, the domain name has services related to site-wide acceleration enabled on Alibaba Cloud (the pan-domain name acceleration may be configured), which conflicts with the front-end web page hosting. You can consider using a third-level domain name or removing the pan-domain name for acceleration and instead configuring the domain name that needs to be accelerated separately.

# Authorize other users to access the service space

For details, please refer to the document: Multiplayer Collaboration in Service Space

# How to use promise/async/await

The uniCloud client callFunction and database-related interfaces will return Promise-type results, please refer to the following writing method:

// index.vue
  <view class="content">
    <button type="default" @click="testThen">promise+then</button>
    <button type="default" @click="testAwait">async+await</button>

  export default {
    data() {
      return {}
    methods: {
      testThen() {
          name: 'test'
        }).then(res => {
        }).catch(err => {
      async testAwait() {
        const res = await uniCloud.callFunction({
          name: 'test'

        // try {
        //   const res = await uniCloud.callFunction({
        //     name: 'test'
        //   })
        //   console.log(res)
        // } catch (err) {
        //   console.error(err)
        // }



# How to judge the fault point when a fault occurs

When there is a problem with your system, how to judge whether it is DCloud or Alibaba Cloud or Tencent Cloud?

First of all, it is stated again that DCloud's services are limited to the development stage. After release and deployment, the access of the application does not go through the DCloud server.

  1. Judging the fault point by domain name
  • unicloud.dcloud.net.cn belongs to DCloud. This website is used during development. When your application goes online, it does not go through the DCloud server. If the domain name can be accessed, but there is a problem with the data connected to Alibaba Cloud or Tencent Cloud under this domain name, then there is also a problem with Alibaba Cloud or Tencent Cloud.
  • bspapp.com, which belongs to Alibaba Cloud. If an error is reported when accessing the domain name, it means that Alibaba Cloud serverless is faulty.
  • tencentcloudapi.com, belonging to Tencent Cloud. If the domain name access error is reported, it means that the Tencent Cloud serverless has failed.

Of course, there is another situation where an error is reported. In fact, it is a problem with the client, including the cross-domain problem of the browser, or the whitelist problem of the domain name of the MiniApp, which makes the client unable to connect to uniCloud. This needs to be solved through configuration, refer to the document: Domain name access configuration for MiniApp and browsers

  1. Determine the fault point through the test system

If the test system is abnormal, it means that the cloud vendor's service is out of order.

These two systems are completely independent. If both systems fail, it means that both cloud vendors fail, not the DCloud service. Again, the published service does not connect to DCloud's server.

When encountering uniCloud faults, just give feedback in the QQ group or forum of uniCloud. Because Alibaba Cloud and Tencent Cloud actually have a dial-up testing system, they will know the fault and solve it in time.

# Common errors

** operation exceeded time limit, cloud database execution time exceeded error**

This error is generally caused by database operation timeout. For details on how to optimize it, please refer to: Performance Optimization

WriteConflict error when using transactions

The execution of the transaction will lock the row, and different transactions executed at the same time will conflict when operating the same row of data, resulting in write failure. Optimize the process as much as possible to avoid transaction conflicts

** An error will be reported when the service space that has not been used for a long time is accessed again **

Possible error messages include: Request cloud function timeout, Response timeout for 10000ms, POST https://api.next.bspapp.com/server -1

This problem is generally caused by the fact that the database has not been accessed for a long time, and the mongoDB WiredTiger storage engine eliminated tables and indexes in memory, causing the database request to time out and causing the cloud function to report an error.

Tencent Cloud reported SIGN_PARAM_INVALID signature is expired error

This problem usually occurs when the Tencent Cloud function is debugged locally, and it is usually caused by the wrong system time of the current development machine

Tencent Cloud reports access token disabled for ANONYMOUS login error

The service space has never uploaded a cloud function, just upload a cloud function

# "certificate has expired" appears when the cloud function accesses other servers through https

This chapter only explains the adjustment of the let's encrypt certificate. In other cases, please check whether the certificate of the corresponding website has expired

The root certificate of let's encrypt expires on September 30, 2021 and switches to a new version of the root certificate. For details, please refer to: DST Root CA X3 Expiration (September 2021). This expiration behavior caused a certificate has expired error when nodejs8 requested a website using a let's encrypt certificate.

There are two solutions:

  1. Upgrade the cloud function to nodejs12, delete the old cloud function, and re-upload after configuring the node version. For details, refer to: cloud function package.json

  2. (Not recommended) Use rejectUnauthorized: false when using uniCloud.httpclient.request. The sample code is as follows:

const https = require('https')
const httpsAgent = new https.Agent({
  rejectUnauthorized: false
await uniCloud.httpclient.request('https://xxx.com/get', {

# "Unauthenticated access is denied" appears when calling cloud functions

If Tencent Cloud is used as the service provider, please check whether the clearStorage operation has been executed on the front end when this problem occurs. clearStorage will clear the token set by Tencent Cloud, resulting in an error when requesting cloud functions.

# Level Protection Authentication


# Use uniCloud.init to initialize the Alibaba Cloud official version service space and report "InvalidSpaceId.NotFound"


# 使用阿里云访问云函数时出现“unknow system error”


# 关于DDoS



On This Page