easyswb
easyswb
  • 发布:2020-04-11 12:13
  • 更新:2020-04-11 12:22
  • 阅读:755

数据库排序不生效

分类:uniCloud

uniapp排序文档地址
我自己写了一个小程序测试排序,
结果返回和期望不一样

'use strict';  
exports.main = async (event, context) => {  
    var param = {};  
    const db = uniCloud.database();  
    const collection = db.collection("t_sys_config2");  
    let query = collection.where({});  
    query = query.orderBy("order2", "asc");  
    query = query.orderBy("order1", "asc");  
    let res = await query.get();  
    res.query = query;  
    console.log("数据库查询结果:" + JSON.stringify(res));  
    return null;  
};  

方式2:颠倒了order2和order1顺序

'use strict';  
exports.main = async (event, context) => {  
    var param = {};  
    const db = uniCloud.database();  
    const collection = db.collection("t_sys_config2");  
    let query = collection.where({});  
    query = query.orderBy("order1", "asc");  
    query = query.orderBy("order2", "asc");  
    let res = await query.get();  
    res.query = query;  
    console.log("数据库查询结果:" + JSON.stringify(res));  
    return null;  
};  

执行结果如下图;
注意,我再res返回结果里面拼接了query对象,

2020-04-11 12:13 负责人:无 分享
已邀请:
easyswb

easyswb (作者) - 前端菜鸟学习中

单个字段没有问题,两个字段就不行.

阿里云.

要回复问题请先登录注册