TypeError: mongodb.db(...).collection(...).find(...).sort is not a function mongodb

Viewed 794

I'm trying to sort collection by name and getting this error.


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);
            });
    };

what am i doing wrong here?

1 Answers

found a solution:

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

Related