Reputation: 173
I have the following user schema
{
"__v" : 26,
"_id" : ObjectId("52b47058fe5e3493a2cf8365"),
"live_sockets" : [
"CEGok0rSz2UtBIHX9DlV",
"s6M45OA0MDBs4aGL9DlW",
"2XiszSuyiPAGr-Ga9ZCN",
"lIFNEeUgXRB6tgvP9ZCO",
"JPtzQOD_52maf6VS9gtb",
"kDL06aXiI8WWlig19gtc",
"75Bt5p6WqgmRcyer9xSm",
"Ge_sKLen32Q91wLW9xSn",
"EpHt3qju34GTZevU_Bsd",
"n0hq0EQAjJOptxdy_qEB",
],
"name" : {
"first" : "Test",
"last" : "User"
},
"notifications_count" : 0,
"role" : 1
}
How can i query a user based on a particular live socket as socket_ids are unique. If i have a variable called current_socket_id how can i find a user which the socket belongs to..?
Upvotes: 0
Views: 80
Reputation: 1196
db.collection.find({"live_sockets" : {$in : [socketId]}},{"name" : 1,"_id":0})
Will give the name for the socket id
Upvotes: 1