aboutsummaryrefslogtreecommitdiff
path: root/part4/blog/models/blog.js
diff options
context:
space:
mode:
Diffstat (limited to 'part4/blog/models/blog.js')
-rw-r--r--part4/blog/models/blog.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/part4/blog/models/blog.js b/part4/blog/models/blog.js
new file mode 100644
index 0000000..28a68e9
--- /dev/null
+++ b/part4/blog/models/blog.js
@@ -0,0 +1,19 @@
+const mongoose = require('mongoose')
+
+const blogSchema = new mongoose.Schema({
+ title: String,
+ author: String,
+ url: String,
+ likes: Number
+})
+
+blogSchema.set('toJSON', {
+ transform: (document, returnedObject) => {
+ returnedObject.id = returnedObject._id.toString()
+ delete returnedObject._id
+ delete returnedObject.__v
+ }
+})
+
+
+module.exports = mongoose.model('Blog', blogSchema)