Saturday 27 May 2017

Uploading image with mongodb node.js and mongoose

I want to be able to upload an image from his computer to the server and the image to be saved in my mongoose schema and also be able show it back to the user. Here is my schema

var mongoose = require("mongoose");

var blogSchema = new mongoose.Schema({
  title: String,
  image: String,
  body: String,
  category: String,
  author: {
  id: {
     type: mongoose.Schema.Types.ObjectId,
     ref: "User"
  },
  username: String
  }, likes: [
  {
     type: mongoose.Schema.Types.ObjectId,
     ref: "likes"
  }
  ],
  comments: [
  {
     type: mongoose.Schema.Types.ObjectId,
     ref: "Comment"
  }
],
created: {type: Date, default: Date.now}
});

module.exports = mongoose.model("Blog", blogSchema);



via fanffis theologiths

No comments:

Post a Comment