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

The WeChat small program cloud development service-side database API specifies the fields to be returned for the records in the return results


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Collection.field / Query.field / Document.field

Specifies the fields that need to be returned for the record in the return result

The method signature is as follows:

function field(definition: object): Collection | Query | Document

The method accepts a required field to specify the field to return

The sample code

Returns the description, done, and progress fields:

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  try {
    return await db.collection('todos').field({
      description: true,
      done: true,
      progress: true
    }).get()
  } catch(e) {
    console.error(e)
  }
}