小程序云开发中数据库数据倒序排列

时间:2026-02-14 20:28:33

1、首先,在添加数据的时候添加个时间字段。

data: {

        title: this.data.title,

        content: this.data.content,

        tag: this.data.tag,

        xx:0,

        oo:0,

        createTime:db.serverDate() //添加该字段

      }

小程序云开发中数据库数据倒序排列

2、然后拉取数据的时候,云函数使用orderby进行排序

exports.main = async (event, context) => {

  try {

    return await db.collection('dbtest').orderBy('createTime','desc').get();

  } catch (e) {

    console.error(e);

  }

}

小程序云开发中数据库数据倒序排列

© 2026 一点知道
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com