想要文档中存在的子文档,来自 MongoDB 数据库

Want a sub document which is present in document, from MongoDB Database

我有一个 Json 数据存储在我的 MongoDB 数据库中,如下所示,

{
        "_id" : ObjectId("5f17109a9013adc57942af2a"),
        "name" : "Demo Name",
        "dob" : "04/01/2000",
        "phone" : "1234567890",
        "email" : "demoname@gmail.com",
        "password" : "0987",
        "cPass" : "0987",
        "location" : "Civil line, Mumbai"
}

我只想要一个名称(子文档),即整个文档中的演示名称:

: Demo Name 

我正在写这个查询:

var employ = await coll.findOne( { "email": "demoname@gmail.com" } );

但它在 var employ 中为我提供了整个文档。我只想在 var employ 中使用名称。我怎样才能用 Mongo Dart 做到这一点。

此查询查找 email 值与“demoname@gmail.com”匹配的元素,找到元素后,它将排除字段,即 _id、dob、phone、email、密码、cPass 和位置。该值仍然是“Demo Name”及其键。

 var employ = await coll
              .find(where.match("email", "demoname@gmail.com").excludeFields([
                "_id",
                "dob",
                "phone",
                "email",
                "password",
                "cPass",
                "location",
              ]))
              .toList();

要删除密钥,我们必须使用以下代码。

var arrayEle = employ[0];          // This statement can store the value in arrayEle from zeroth position.
var empName = arrayEle['name'];    // This statement can remove the key "name" and only value of the key i.e "Demo Name" gets stored in empName variable.   
  print(empName);                  // This statment print the value stored in empName which is "Demo Name".