如何从数组中删除重复的条目?
在下面的示例中,"Algorithms in C++"
出现两次.
In the following example, "Algorithms in C++"
is present twice.
$unset
修饰符可以删除特定字段,但是如何从字段中删除条目?
The $unset
modifier can remove a particular field but how to remove an entry from a field?
{
"_id" : ObjectId("4f6cd3c47156522f4f45b26f"),
"favorites" : {
"books" : [
"Algorithms in C++",
"The Art of Computer Programming",
"Graph Theory",
"Algorithms in C++"
]
},
"name" : "robert"
}
您要做的是使用map reduce来检测和计数重复的标签.然后使用$set
替换基于{ "_id" : ObjectId("4f6cd3c47156522f4f45b26f"),
的整本书
What you have to do is use map reduce to detect and count duplicate tags .. then use $set
to replace the entire books based on { "_id" : ObjectId("4f6cd3c47156522f4f45b26f"),
这里已经讨论过旅行时间..请参见
This has been discussed sevel times here .. please seee
http://csanz.posterous.com/使用mongodb-mapreduce查找重复项
http://www.mongodb.org/display/DOCS/MapReduce
How to remove duplicate record in MongoDB by MapReduce?