Reputation: 13
class createuser {
constructor(url){
this.userid = this.getuserid()
this.user = {name:url[2],userid:this.userid,notes:{}}
this.passwordobj = {userid: this.userid,password: url[3]}
}
async getuserid(){
const DBclient = new mongoclient(uri)
try {
const database = DBclient.db('NotesApp');
const Users = database.collection('Users');
// Query for a userdata that has the title 'Back to the Future'
const userdata = await Users.findOne({},{sort:{userid: -1}});
return userdata.userid+1
} finally {
// Ensures that the client will close when you finish/error
await DBclient.close();
}
}
}
const newuser = new createuser(["","signup","kushi","password123"])
console.log(newuser);
this is my code and it returns this :
PS C:\Users\7A7z\Documents\node> node NotesApiv2
createuser {
userid: Promise { <pending> },
user: { name: 'kushi', userid: Promise { <pending> }, notes: {} },
passwordobj: { userid: Promise { <pending> }, password: 'password123' }
}
it returns pending even though there is a await
i expected the userid to be one above the highest userid in the database
Upvotes: 0
Views: 17