在包含 MongoDB 的子文档中查找项目

Finding item in subdocument with MongoDB

我正在尝试搜索当前项目:

我尝试了以下方法:{participants: {userEmail: 'test@gmail.com'}}

但它没有 return 任何东西。 Im mongoDB compass 我在查询历史记录中得到以下信息:

我将如何编写查询以查找突出显示的电子邮件地址?或者包含该电子邮件地址的文档。

谢谢。

您的查询要求 participants 恰好是一个对象,例如:

{userEmail: 'test@gmail.com'}

你想做的事情可以通过 dot notation:

来实现
{ 'participants.userEmail': 'test@gmail.com'}}