Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(script): add script to remove permissionList.read key from the db #2190

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to change but this is equivalent to 'permissionList.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 }
Comment on lines +28 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again no need to change but this is equivalent to this:

Suggested change
{ $unset: { 'permissionList.$[elem].read': 1 } },
{ arrayFilters: [{ 'elem.read': { $exists: true } }], multi: true }
{ $unset: { 'permissionList.$[].read': 1 } },
{ 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)
}