Skip to content

Commit

Permalink
Merge pull request #51 from wearefuturegov/feature/index-checks
Browse files Browse the repository at this point in the history
Check to make sure the latest indexes are present
  • Loading branch information
apricot13 authored Jul 9, 2024
2 parents a6e4f63 + b11e554 commit 7ad3383
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ module.exports = {
} else {
logger.info(`Connected to the "${dbName}" database`)
}

// ensure that the location index exists
const indexName = "service_at_locations.location.geometry_2dsphere"
try {
const indexExists = await db
.collection("indexed_services")
.indexExists(indexName)

if (!indexExists) {
logger.warn(
`The index ${indexName} does not exist on your collection, please run prepare-indices script to create it or you will not return correct results.`
)
}
} catch (err) {
logger.error(`Unable to check for location index ${err}`)
}

cb(db)
})
.catch(err => {
Expand Down

0 comments on commit 7ad3383

Please sign in to comment.