云开发数据库collection.field 数组字段 project.slice方法使用不了?
发布于 8 年前 作者 wjiang 3438 次浏览 来自 官方Issues
const $ = db.command.project
await db.collection('chat').where({
    _id: event.id
  }).field({
    _id: true,
    chatReqUserId: true,
    chatResUserId: true,
    record: $.slice(-2)
  }).get()
const $ = db.command.project
await db.collection('chat').where({
    _id: event.id
  }).field({
    _id: true,
    chatReqUserId: true,
    chatResUserId: true,

    record: {

tags: $.slice(-2)

   }

  }).get()


报错信息: Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 9e68d720-fa24-11e9-b2dd-525400e8849e, cloud function service error code -504002, error message errCode: -501007 invalid parameters | errMsg: [InvalidParameterValue.QueryProjection] Query projection entered in the request is illegal. Please check your request, but if the problem persists, contact us.; ; at cloud.callFunction api; 

文档地址: https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/database/collection.field.html

两种方法都测试过了,返回了同样的报错信息,然后在command列表文档下也找不到project这个方法,不知道是否是该方法已被废除,求大佬帮忙,万分感谢

2 回复

const $ = db.command.aggregate

db.collection(‘test’).aggregate()

.project({

a: $.slice([’$a’, 2]),

})

.end().then(res => {

console.log(res)

})

回到顶部