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

The SDK database gets a reference to the collection


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Database.collection(name: string): Collection

Support: small programs, cloud functions, web

Gets a reference to the collection. The method accepts a name parameter that specifies the name of the collection to be referenced.

Parameters

name: string

The name of the collection

Returns a value

Collection

Example code: Small terminal

const db = wx.cloud.database()
const todosCollection = db.collection('todos')

Example code: Cloud function side

const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const todosCollection = db.collection('todos')