我正在使用MongoDB聚合框架展开一个数组,并且该数组有重复项,我需要在进行进一步分组时忽略这些重复项.
我怎样才能做到这一点?
如何从数组中删除重复的条目?
在下面的例子中,"C++中的算法"被添加两次.
$ unset修饰符删除特定字段但如何从字段中删除条目?
> db.users.find()
{ "_id" : ObjectId("4f6cd3c47156522f4f45b26f"),
"favorites" : { "books" : [ "Algorithms in C++",
"The Art of Computer Programmning",
"Graph Theory",
"Algorithms in C++" ] },
"name" : "robert" }
Run Code Online (Sandbox Code Playgroud) mongodb ×2