【问题标题】:TypeError: mongodb.db(...).collection(...).find(...).sort is not a function mongodbTypeError: mongodb.db(...).collection(...).find(...).sort 不是函数 mongodb
【发布时间】:2020-02-28 16:11:41
【问题描述】:

我正在尝试按名称对集合进行排序并收到此错误。


handleSortByName = () => {
        const mongodb = Stitch.defaultAppClient.getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas');
        mongodb
            .db('users')
            .collection('userDetails')
            .find()
            .sort({ name: -1 })
            .then((users) => {
                console.log(users);
            })
            .catch((err) => {

                console.log(err);
            });
    };

我在这里做错了什么?

【问题讨论】:

  • 你得到的错误是什么?
  • TypeError: mongodb.db(...).collection(...).find(...).sort 不是函数

标签: mongodb mongodb-stitch


【解决方案1】:

找到了解决办法:

.db('users')
            .collection('userDetails')
            .find({}, { sort: { name: -1 } })
            .asArray()

【讨论】:

    猜你喜欢
    • 2019-08-04
    • 2018-09-17
    • 2019-05-28
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 2012-08-20
    相关资源
    最近更新 更多