-2

based on some system arch, i may need to update multiple collection under some name rule, e.g. [m_aaaa_info], [m_aaab_info] .etc

thus i may need to update all the collections named by [m_*_info], with the same select & update conditions like update({"isDeleted": false}, {$set:{"isDeleted": false}})

so, is there any tool/commend can do this operations? e.g. db.getCollection('m_*_info').update({"isDeleted": false}, {$set:{"isDeleted": false}}, upset=false, multi-update=true)

  • I've tried a basic & a little bit clumsy way... use spring mongodb jar method to get all the collections' name, store into a list with system config collections skipped, loop the list and hard code the update cmds... it's quite a terrible work to do that for over 100 target collections :( – chen steven Nov 24 '17 at 03:39

1 Answers1

0
var c = db.getCollectionNames();
c.forEach(function(name) {
            if (/m_[a-z]*_info/i.test(name)) {
                db[name].update({
                        "isDeleted": false
                    }, {
                        $set: {
                            "isDeleted": true
                        }
                    }
                }
            })
R. S.
  • 402
  • 5
  • 17