Home > Software design >  I wanna find an Schema name
I wanna find an Schema name

Time:10-05

I have an collection in mongoose. it's name member and I use the findOne for find one like this : var member = findOne(name , (err , docs)=>{console.log(docs)}) and then I wanna to find more things by member var like : momber.targetNmae in Schema and it not work.

CodePudding user response:

You shouldn't be assigning the value of an async function that doesn't return anything. Try using async/await to make it more readable. Chain your query after the Collection name like:

User.find();

let doc; 

try {
  doc = await User.findOne({ name: name });
} catch (err) {
  console.log(err);
};
console.log(doc);

And without async/await:

User.findOne({ name: name }, (err, doc) => {
  if (!err) {
    console.log(doc);
  }
});
  • Related