P
P
Pavlo Ponomarenko2018-09-01 15:57:53
MongoDB
Pavlo Ponomarenko, 2018-09-01 15:57:53

Why does mongoose hang when creating an element?

console.log('searching');

let user = await UserModel.findOne(params);
console.log('search finished');

if (user == null) {
    console.log('nothing');
    user = await new UserModel(params).save(); // <== на этой строке зависает
    console.log('created');
}

return user;

Why can it hang when trying to create an element? Search is made normally and sessions work. Doesn't write any errors. The table itself is created (if fields with indexes are used). To be honest, I don't quite understand how to debug this.
If you make a request directly in the same place, then everything will work correctly:
const data = await db().collection("users").insertOne(params);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavlo Ponomarenko, 2018-09-01
@TheShock

I found the reason - it turns out I was stupid.
I had a pre-save method in the schema and forgot to call next on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question