V
V
Valera Velery2019-11-09 11:56:12
JavaScript
Valera Velery, 2019-11-09 11:56:12

Mongodb why FindOne works but Find doesn't?

here is the code

if (req.url === '/login' && req.method === 'POST') {
        console.log('login');
        res.setHeader('content-type','application/json; charset=utf-8');
        res.setHeader('Access-Control-Allow-Origin','*');
        let data = '';
        req.on('data',(dataSumbol) => {
            data+=dataSumbol.toString();
        })
        req.on('end',async () => {
            data = JSON.parse(data);
            let infoBD = await db.find({email:data.email,password:data.password});
            console.log('data',infoBD);
            if (!infoBD) {
                res.end(JSON.stringify({
                  resultCode:1,
                  textErorr:'ivalid login or password',
                }));
                return
            } else {
                res.end(JSON.stringify(infoBD));
            }
        })
        return
    }

rejection text
UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'NativeTopology'
| property 's' -> object with constructor 'Object'
| property 'sessionPool' -> object with constructor 'ServerSessionPool'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
h88p, 2019-11-09
@valera213123

In the condition, check through infoDB.length, because you receive an array and even if it is empty, you will always have true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question