Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program cloud development service-side database API to create a collection


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Database.createCollection

Creating a collection, if it already exists, fails to create

The function signature is as follows:

function createCollection(): Promise<Result>

Returns a description of the value

The results of Promise's resolve and reject are defined as follows:

Description of the results
resolve The results of the query, the Result definition can be found below
reject The reason for the failure

Result description

The result of Promise Resolve is an object that contains only errMsg

The sample code

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  return await db.createCollection('todos')
}