# db.collection

Gets a reference to data collection.

The method signature is shown as below:

function collection(name: string): Collection

The method accepts a name parameter to specify the name of the collection to be referenced.

Sample code

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const todosCollection = db.collection('todos')
点击咨询小助手