Nodejs - Express custom session data not saving correctly

I am trying to store some data in my users session using express-session.

The below is a snippet of code that I am running into issues with.

As you can see I am adding alot of items into req.session, and at the end of the for loop I send back res.json(200, req.session).

In the response on the client, you see the session with ALL of the data I added, but in the database none of that is stored.

} else {
               req.session.user = {
                   username: req.body.username,
                   permissions: {},
                   authorized: true
               };
               for (var i = 0; i < doc.length; i++) {
                   req.session.user.permissions[doc[i]._id] = {
                       _id: doc[i]._id,
                       name: doc[i].name,
                       roles: doc[i].permissions[0].roles
                   };
                   if (i == (doc.length - 1)) {
                       req.session.user.currentapplication = req.session.user.permissions[req.body.application]
                       res.json(200, req.session);
                   }
               }

I have been able to take this line out inside the if:

 req.session.user.currentapplication = req.session.user.permissions[req.body.application]

This works perfectly, all the data I set earlier is stored in the database but obviously not the users current application.

I have tried another approach where req.session.user.permissions is an array, with application objects inside but it seems trying to add an array or objects inside the for loop kill it.

Any ideas would be appreciated, thanks.