Skip to content

Commit

Permalink
Add new script to create the collection without using docker init com…
Browse files Browse the repository at this point in the history
…mands
  • Loading branch information
apricot13 committed Oct 25, 2023
1 parent e2085df commit 03c3c98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/prepare-collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require("dotenv").config()
const { connect } = require("../db")

connect(async db => {
const collections = await db
.listCollections({ name: "indexed_services" }, { nameOnly: true })
.toArray()

const indexedServicesDb = collections.some(a => a.name === "indexed_services")

if (!indexedServicesDb) {
try {
await db.createCollection("indexed_services")
console.log("✅ 'indexed_services' Collection created successfully")
process.exit()
} catch (e) {
console.log(e)
throw e
}
} else {
console.log("✅ 'indexed_services' Collection already exists")
process.exit()
}
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"start": "node index.js",
"dev": "NODE_ENV=development nodemon index.js",
"test": "jest",
"prepare-collection": "node lib/prepare-collection",
"prepare-indices": "node lib/prepare-indices"
},
"test": "exit 0",
Expand Down

0 comments on commit 03c3c98

Please sign in to comment.