使用DBRef字段查询mongodb文档

时间:2019-05-09 16:29:48

标签: mongodb mongodb-query

我有一个如下用户文档:

{
"_id" : ObjectId("5ccfe299902bb32f5a194ed7"),
"email" : "johnDoe@gmail.com",
"name" : "David",
"businessName" : "Test",
"phone" : "123123",
"createdTime" : ISODate("2019-05-09T11:11:13.353Z"),
"updatedTime" : ISODate("2019-05-09T11:11:28.336Z"),
"webinarSignups" : [
    DBRef("webinarSignups", ObjectId("5ccfe298902bb32f5a194ed6"))
],
"infoSignups" : [
    DBRef("infoSignups", ObjectId("5ccfe2c2902bb32f5a194eda"))
 ]
}

webinarSignups文档:

{
"_id" : ObjectId("5ccfe298902bb32f5a194ed6"),
"email" : "example@gmail.com",
"webinarId" : "STAR-ELO-WEBINAR",
"contactName" : "John",
"businessName" : "Test",
"jobTitle" : "Test",
"phoneNo" : "123123",
"refPage" : "",
"createdTime" : ISODate("2019-05-09T11:15:06.478Z"),
}

如何找到具有webinarId : STAR-ELO-WEBINAR的用户

查询即时通讯使用:

db.user.find({"webinarSignups": { $elemMatch: {$ref: "webinarSignups", "webinarId" : "STAR-ELO-WEBINAR" } }})

但是它不返回任何记录。我在这里做错了什么?我是mongodb的新手。因此,非常感谢您的支持。预先感谢

0 个答案:

没有答案