I am new to writing MongoDb queries to fetch data. I am trying to write a nested query to fetch user data from the sessions collections.
Basically I am trying to get db.sessions.passport.user.email
.
But I am unable to get the required value which is vdipali8@gmail.com
.
Query that I am using is as follows:
db.sessions.find({"session.passport.user.email":"vdipali8@gmail" });
Following is my sessions collection:
db.sessions.find().pretty()
{
"_id" : "xi8sMgfYywLJdoZPpUHKa3Uau3wY",
"session" : "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":{\"_id\":\"5750ec592ecb2c0bfb5d39\",\"email\":\"vdipali8@gmail.com\",\"lastName\":\"Vl\",\"firstName\":\"Dipali\",\"facebookid\":\"13596511\",\"__v\":0}}}",
"expires" : ISODate("2016-06-17T02:47:45.042Z")
}
The sessions collection is generated as follows in my express Node server file:
app.use(session({ secret: 'keyboard cat',
store: new MongoStore({
mongooseConnection: mongoose.connection,
collection: 'sessions'
})
}));
and the schema for the same is declared as follows:
var SessionSchema = new Schema({
session: String,
expires: String
}, {collection: 'sessions'}
);
Yes, I am trying to retrieve the "email" along with few other fields.