How can I store an image into MongoDB using the below scenario.
- Below is my product schema, I want to add another field image into it and manually post the image along with the other fields using Product.create or Product.insertMany method (example below).
- Inserting image manually means I have grabbed some product images from Google but I am unable to figure out how to store them in MongoDB and use them in my front end.
- My goal is just to display all the products using the frontend React app along with the image and its details.
const mongoose = require('mongoose');
const productSchema = mongoose.Schema({
name: String,
category: String,
price: Number,
});
const Product = mongoose.model('Product', productSchema);
module.exports = Product;
// Product.insertMany(
// [
// { name: 'Shoe one', category: 'Shoes', price: 3599 },
// { name: 'Shirt one', category: 'Upperwear', price: 380 },
// ],
// (err) => {
// if (err) console.log('error');
// }
// );