我有以下用户架构
{
"__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
}
如何基于特定的实时套接字查询用户,因为socket_ids是唯一的。 如果我有一个名为current_socket_id的变量,我怎样才能找到套接字所属的用户..?
答案 0 :(得分:1)
db.collection.find({"live_sockets" : {$in : [socketId]}},{"name" : 1,"_id":0})
将给出套接字ID的名称