Hi,

I want to my code work as below:
1. save Chest object to db
2. Then save all contents belong to this chest to db (have logic to add new
filed to content before saving)
3. Then return response with chest + new contents info

But the real code does not work as I expected, the code is:

chestApi = createChestWithContents{
>     var chest = req.body;
>     var contents = req.body.contents;
>     chest.save(function(err, chest) {
>            async.each(contents, function(content) {
>                      content.save()....
>             }, function(done) {
>                    return res.status.(200).. ///OK
>             });
>     });
> }


When I use postman to test, the method end up without any response returned
due to asynchronous methods(even when I used async to wait till the loop
finish), cannot figure out how to do those stuff synchronously.
-- 
Nguyen Hai Duy
Mobile : 0914 72 1900
Skype: nguyenhd2107

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAGOR8-2A8LGnQugzH92quVwEDCiGOBExp7_mq%3DAtjp-LaDt4_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to