Skip to content

Commit

Permalink
docs: remove dangling commas from mongo scripts (#794)
Browse files Browse the repository at this point in the history
dangling commas cause the mongo shell to throw invalid syntax errors
  • Loading branch information
karrui authored Dec 7, 2020
1 parent 7b9c3c1 commit 3738df4
Showing 1 changed file with 17 additions and 52 deletions.
69 changes: 17 additions & 52 deletions docs/MONGODB.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,12 @@ function unlistFormFromExamples(id) {
if (!ObjectId.isValid(id)) throw new Error('Id is not valid')
const formId = ObjectId(id)
const result = db.forms.update(
{
_id: formId,
},
{
$set: {
isListed: false,
},
},
{ _id: formId },
{ $set: { isListed: false } }
)
if (result.nMatched === 0) throw new Error(`Form ${formId} not found`)

return db.forms.find({
_id: formId,
})
return db.forms.find({ _id: formId })
}
// unlistFormFromExamples("form id")
```
Expand Down Expand Up @@ -75,17 +67,15 @@ function unlistFormArrayFromExamples(ids) {
*/
function createAgency(shortName, fullName, logoUrl, emailDomains) {
if (!(emailDomains instanceof Array))
throw new Error(
`Email domains not in an array, emailDomains: ${emailDomains}`,
)
throw new Error(`Email domains not in an array, emailDomains: ${emailDomains}`)

return db.agencies.insert([
{
shortName: shortName,
fullName: fullName,
logo: logoUrl,
emailDomain: emailDomains,
},
emailDomain: emailDomains
}
])
}

Expand All @@ -103,26 +93,16 @@ function createAgency(shortName, fullName, logoUrl, emailDomains) {
function migrateAllForms(oldAdminEmail, newAdminEmail) {
const oldAdmin = db.users.findOne({ email: oldAdminEmail })
if (oldAdmin === null)
throw new Error(
`Could not find any user with the email address: ${oldAdminEmail}`,
)
throw new Error(`Could not find any user with the email address: ${oldAdminEmail}`)

const newAdmin = db.users.findOne({ email: newAdminEmail })
if (newAdmin === null)
throw new Error(
`Could not find any user with the email address: ${newAdminEmail}`,
)
throw new Error(`Could not find any user with the email address: ${newAdminEmail}`)

return db.forms.update(
{
admin: oldAdmin._id,
},
{
$set: {
admin: newAdmin._id,
},
},
{ multi: true },
{ admin: oldAdmin._id },
{ $set: { admin: newAdmin._id } },
{ multi: true }
)
}
// migrateAllForms("oldAdmin", "newAdmin")
Expand All @@ -142,37 +122,22 @@ function migrateOneForm(id, oldAdminEmail, newAdminEmail) {

const oldAdmin = db.users.findOne({ email: oldAdminEmail })
if (oldAdmin === null)
throw new Error(
`Could not find any user with the email address: ${oldAdminEmail}`,
)
throw new Error(`Could not find any user with the email address: ${oldAdminEmail}`)

const newAdmin = db.users.findOne({ email: newAdminEmail })
if (newAdmin === null)
throw new Error(
`Could not find any user with the email address: ${newAdminEmail}`,
)
throw new Error(`Could not find any user with the email address: ${newAdminEmail}`)

let form = db.forms.findOne({ _id: formId, admin: oldAdmin._id })
if (form === null)
throw new Error(
`Could not find form ${id} that belongs to ${oldAdminEmail}`,
)
throw new Error(`Could not find form ${id} that belongs to ${oldAdminEmail}`)

db.forms.update(
{
_id: formId,
admin: oldAdmin._id,
},
{
$set: {
admin: newAdmin._id,
},
},
{ _id: formId, admin: oldAdmin._id },
{ $set: { admin: newAdmin._id } }
)

return db.forms.find({
_id: formId,
})
return db.forms.find({ _id: formId })
}
// migrateOneForm("form id", "oldAdmin", "newAdmin")
```

0 comments on commit 3738df4

Please sign in to comment.