Answer the question
In order to leave comments, you need to log in
MongoDB - Why is Users.findOne undefined?
Hello!
With this code, I want to find an entry in a collection:
var sameLogins = Users.findOne({login: 'a'});
console.log(sameLogins);
Answer the question
In order to leave comments, you need to log in
The code above was needed to check user logins for uniqueness.
As it turns out, the meteor has built-in tools for this.
I figured it out thanks to this documentary:
https://docs.meteor.com/api/passwords.html#Account...
This is what the code looks like:
Because Users.findOne is an asynchronous method and the result should be output in a callback or a promise?
var sameLogins = Users.findOne({ login: "a" }, (err, user) => {
if (err) console.log(err);
console.log(user);
});
var sameLogins = Users.findOne({ login: "a" })
.then(user => console.log(user))
.catch(err => console.log(err));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question