# db.command.push

Update command. Appends one or more values to the end of an array when the value of a field is the array. Alternatively, if the value of a field is empty, creates the field and sets the array as the incoming value.

Function signature:

function push(values: any[]): Command

Sample code

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
  try {
    return await db.collection('todos').doc('doc-id').update({
      data: {
        tags: _.push(['mini-program', 'cloud'])
      }
    })
  } catch(e) {
    console.error(e)
  }
}