Intellishell 重复文档清理

我正在使用 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}})   
    
})

})

jinjing003 回答:Intellishell 重复文档清理

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/227395.html

大家都在问