# db.command.unshift

Update command. Prefix one or more values to the head 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 unshift(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: _.unshift(['mini-program', 'cloud'])
      }
    })
  } catch(e) {
    console.error(e)
  }
}
点击咨询小助手