问题描述
我正在使用 Studio3T 的 Intellishell。 我希望修改我的“重复清理”脚本以运行所有客户,而不需要为每个客户单独运行脚本。如果该客户有相同的记录,则仅将重复项视为重复项。客户之间的相同记录不被视为重复,不应清除。
db.assessment_dictionary.find({customer_id:"90uwjff0jjio89302"}).forEach(function(ad) {
db.assessments.aggregate(
[
{$match:{dictionary_id:ad._id}},{"$group" : { "_id": {customer_id:"$customer_id",dictionary_id:"$dictionary_id",student_id:"$student_id",school_year:"$school_year",term_name:"$term_name",test_grade:"$test_grade",test_score:"$test_score"},scores: {$addToSet: "$test_score"},uniqueIds: { $addToSet: "$_id" },"count": { "$sum": 1 } } },{"$match": {"_id" :{ "$ne" : null },"count" : {"$gt": 1} } }
],{allowdiskUse:true}
).forEach(function(doc) {
var ids = []
for (var i = 1; i<doc.uniqueIds.length; i++) {
ids.push(doc.uniqueIds[i]);
if (i%100==0) {
db.assessments.remove({_id:{$in:ids}})
ids = [];
}
// print ('Delete');
// } else {
// print ('Keep');
// }
}
db.assessments.remove({_id:{$in:ids}})
})
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)