0

这是我的数据库条目结构,它有一个名为friends的嵌套文档,我想使用mongo_dart比较dart中两个不同_id的朋友列表

{
"_id" : ObjectId("60ae06074e162995281b4666"),
"email" : "one@one.com",
"emailverified" : false,
"username" : "one@one.com",
"displayName" : "complete n00b",
"phonenumber" : "",
"dob" : "",
"points" : 0,
"friends" : [
    {
        "username" : "three@one.com",
        "sent" : ISODate("2021-05-26T10:01:30.616Z")
    },
    {
        "username" : "six@one.com",
        "sent" : ISODate("2021-05-26T10:43:16.822Z")
    }
]

}

这是我的代码,但我没有得到任何回报

Future<Map> commonFriends(store, myObjectId, theirObjectId) async {
  var commonList = await store.aggregate([
    {
      '\$project': {
        'friends': 1,
        'commonToBoth': {
          '\$setIntersection': [
            {'_id': myObjectId, 'friends': '\$username'},
            {'_id': theirObjectId, 'friends': '\$username'}

          ]
        },
      }
    }
  ]);
  return commonList;
}

我从 db.dart 收到一个错误,它是 mongo_dart 包的一部分。错误是“发生异常。地图(4 项)”

4

0 回答 0