aboutsummaryrefslogtreecommitdiffstats
path: root/model.js
diff options
context:
space:
mode:
Diffstat (limited to 'model.js')
-rw-r--r--model.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/model.js b/model.js
new file mode 100644
index 0000000..7eba2a4
--- /dev/null
+++ b/model.js
@@ -0,0 +1,32 @@
+"use strict";
+
+const mongoose = require("mongoose");
+mongoose.Promise = global.Promise;
+const db = {};
+db.mongoose = mongoose;
+db.url = "mongo:27017";
+
+const blogPostModel = mongoose.model(
+ "blogPost",
+ mongoose.Schema(
+ {
+ title: String,
+ description: String,
+ published: Boolean,
+ },
+ { timestamps: true }
+ )
+);
+
+function dbInit() {
+ db.mongoose
+ .connect(db.url, { useNewUrlParser: true, useUnifiedTopology: true })
+ .then(() => {
+ console.log("successfully connected to db");
+ })
+ .catch((err) => {
+ console.log("cannot connect to the database: ", err);
+ process.exit(1);
+ });
+}
+module.exports = dbInit;