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: add script for unlisting array of forms #714

Merged
merged 1 commit into from
Nov 24, 2020
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
28 changes: 28 additions & 0 deletions docs/MONGODB.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ function unlistFormFromExamples(id) {
// unlistFormFromExamples("form id")
```

```javascript
/**
* Unlist an array of forms from the examples page
* @param {String[]} ids of the forms. These can be any string
* where the first sequence of 24 consecutive alphanumerics is the
* form ID, e.g. the form link.
*/
function unlistFormArrayFromExamples(ids) {
const formIdRegex = /[0-9a-fA-F]{24}/
// Wrap all ids in ObjectId
const objectIds = []
for (let id of ids) {
const parsed = formIdRegex.exec(id)
if (parsed) {
objectIds.push(ObjectId(parsed[0]))
} else {
throw new Error(`${id} does not contain a valid form ID.`)
}
}
const result = db
.getCollection('forms')
.updateMany({ _id: { $in: objectIds } }, { $set: { isListed: false } })
return `${ids.length} forms given, ${result.matchedCount} matched, ${result.modifiedCount} modified`
}
// const ids = ['https://some.url/5f8817b7bde9d4002a800d78', 'some.url/#!/5f9a587b119c07002b56124f']
// unlistFormArrayFromExamples(ids)
```

- **Create new agency**

```javascript
Expand Down