Answer the question
In order to leave comments, you need to log in
How to make a lookup in MongoDB return an empty array?
Hello, Please tell me what am I doing wrong?
How to do a lookup in MongoDB?
You need to do a search on the fields (login, password) ....
They are in the nested object (user) .
Why is an empty array returned?
D.B.
{
_id: ObjectId("5f4d31dc5e7b610a0c7914d2")
user: {
login: "qwerty",
password: "123"
}
}
const UserSchema = new Schema({
user: {
login: String,
password: String
},
jwt: String
});
router.post('/users/user/:login', (req,res) => {
User.find({login: req.body.login, password: req.body.password})
.then((data) => {
console.log(data);
})
});
Answer the question
In order to leave comments, you need to log in
const UserSchema = new Schema({
user: {
login: String,
password: String
},
jwt: String
});
user: { user: {login, password} }
const UserSchema = new Schema({
login: String,
password: String,
jwt: String
});
// если так, то сработает
User.find({login: req.body.login, password: req.body.password})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question