Skip to content

Commit

Permalink
docs(script): add script to remove permissionList.read key from the db (
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui authored Jun 17, 2021
1 parent bef9b3a commit a4207a8
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable */

// Number of forms with permissionList.read key - expect 0 after running update
db.forms.count({
permissionList: { $elemMatch: { read: { $exists: true } } }
})

{
// Number of objects in permissionList with read key - expect 0 after running update
const permissionListWithReadKey = [
{
$match: {
permissionList: { $elemMatch: { read: { $exists: true } } }
},
},
{ $project: { permissionList: 1 } },
{ $unwind: '$permissionList' },
{ $match: { 'permissionList.read': { $exists: true } } },
{ $count: 'numObjs' }
]

db.getCollection('forms').aggregate(permissionListWithReadKey)
}

// Update - Remove read key
db.forms.update(
{ 'permissionList.read': { $exists: true } },
{ $unset: { 'permissionList.$[elem].read': 1 } },
{ arrayFilters: [{ 'elem.read': { $exists: true } }], multi: true }
)


// Check again, should be 0.
db.forms.count({
permissionList: { $elemMatch: { read: { $exists: true } } }
})

// Check again, should be 0
{
// Number of objects in permissionList with read key - expect 0 after running update
const permissionListWithReadKey = [
{
$match: {
permissionList: { $elemMatch: { read: { $exists: true } } }
},
},
{ $project: { permissionList: 1 } },
{ $unwind: '$permissionList' },
{ $match: { 'permissionList.read': { $exists: true } } },
{ $count: 'numObjs' }
]

db.getCollection('forms').aggregate(permissionListWithReadKey)
}

0 comments on commit a4207a8

Please sign in to comment.