I am still in learning stage of Node.js and Moongoose and i have a scenario where in
- I am taking value(ABC) from form submit.It is a user's Name
- Then i am searching for that name in users collection(User)
- Fetch that user and write its ObjectID in another schema(article) using ref.
My logic:
article.owner = User.findOne({ 'name' : 'ABC' })
.exec(function (err, user){
return user
})
But it is not returning results. I referred some other answers and tried async.parallel but still i am not able to save ABC user's objectID in article schema at article.owner i am always getting null.
Please suggest me any other better ways.