dimanche 29 mars 2015

How to find the list of active user based on the session in mongo db collection

I have a list of user IDs and I need to find the active users from the list in the session collection by passing the list of user IDs. The session collection looks like below: This is created automatically using the express js session handler.



{
"_id" : "sXfI3vMxkZzsTkxuovUFONYA",
"session" : "{\"cookie\":{\"originalMaxAge\":14399998,\"expires\":\"2015-03-28T17:24:18.996Z\",\"secure\":true,\"httpOnly\":true,\"path\":\"/\"},\"lastAccess\":1427549058996,\"dbname\":\"abc\",\"userid\":\"54f5bfb0336a15084785c379\"}",
"expires" : 1427563458000
}
{
"_id" : "sXfI3vMxkZzsTkxuovUFONYB",
"session" : "{\"cookie\":{\"originalMaxAge\":14399998,\"expires\":\"2015-03-28T17:24:18.996Z\",\"secure\":true,\"httpOnly\":true,\"path\":\"/\"},\"lastAccess\":1427549058996,\"dbname\":\"abc\",\"userid\":\"54f5bfb0336a15084785c371\"}",
"expires" : 1427563458000
}
{
"_id" : "sXfI3vMxkZzsTkxuovUFONYC",
"session" : "{\"cookie\":{\"originalMaxAge\":14399998,\"expires\":\"2015-03-28T17:24:18.996Z\",\"secure\":true,\"httpOnly\":true,\"path\":\"/\"},\"lastAccess\":1427549058996,\"dbname\":\"abc\",\"userid\":\"54f5bfb0336a15084785c370\"}",
"expires" : 1427563458000
}


I have an user id list like ["54f5bfb0336a15084785c379","54f5bfb0336a15084785c371"] as "userList". I am querying like this:



db.sessions.find({"session.cookie.userid":{$in:userList}})`


and I am getting null as result.


I am able to get the result when querying like this:



db.sessions.find({"session":/54f5bfb0336a15084785c379/})


But I need to find the list of active users from the users list using node js mongodb client. Can anyone help me with this please?


Aucun commentaire:

Enregistrer un commentaire