云数据库聚合问题?
发布于 4 年前 作者 guiyingliu 5455 次浏览 来自 官方Issues

我在聚合中通过 $items[0] 想要拿到这个数组字段中的第一个元素, 结果type没有输出, 也没有报错.

请问, 这是哪里出了问题?

.project({

planDate:

items:

type: '$items[0]'

})

2 回复
const db = cloud.database()
const $ = db.command.aggregate
const _ = db.command   

 let res = await db.collection('plan')
      .aggregate()
      .project({
        first: $.arraElemAt(['$content', 0]),
      })
      .end()

结果报错了: 说没有这个方法

TypeError: $.arraElemAt is not a function

是这个意思吗?

普通数据类型不知道怎么弄, $items.0 和$items[0]都不行

回到顶部