Mongoose: Get full list of users

前端 未结 8 1121
遇见更好的自我
遇见更好的自我 2020-12-12 12:54

I have tried to use Mongoose to send the list of all users as follows:

server.get(\'/usersList\', function(req, res) {
    var users = {};

    User.find({},         


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 13:32

    To make function to wait for list to be fetched.

    getArrayOfData() {
        return DataModel.find({}).then(function (storedDataArray) {
            return storedDataArray;
        }).catch(function(err){
            if (err) {
                throw new Error(err.message);
            }
        });
    }
    

提交回复
热议问题