微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Intellishell 重复文档清理

如何解决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}})   
    
})

})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。