0
votes

Am trying to fetch all session document based on user id so that i can redirect after they are successfully logged in any machine by storing the variable named like lastviewed and date in session document, Please guide me further am using connect-mongo for session storage

{ 
"_id" : "RMZQdKfh_qiBaJ66w-ojFmuKL92ymNN-", 
"session" : "{\"cookie\":{\"originalMaxAge\":86399996,\"expires\":\"2017-03-17T14:29:56.298Z\",\"secure\":false,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":\"58c9443cfaca995c0c14d129\"},\"lastviewed\":\"/api/companies\"}", 
"expires" : ISODate("2017-03-17T14:29:56.298+0000")
}

From the above document i just want query like this { 'session.passport.user':'user_id' }

1
I edited the question please don't down voteKrishna
why dont you store session as an object? That way it will be possible to access nested fields using . (dot) operatorAtish
i thought the express-session library it self store that session like that @AstroKrishna

1 Answers

0
votes

I figured it out connect-mongo stringifies and then store session as a string, after configured like below i can able to query.

store: new MongoStore({
        mongooseConnection: db.connection,
        collection: config.sessionCollection,
        stringify: false
    })

https://github.com/jdesboeufs/connect-mongo#more-options