So I'm working on a personal project for a shopping site clone and I am trying to design a function to add products to the database. Eventually, in this project I want to have a seller 'store' page where all products from a specific seller will be displayed. I read that when using NoSQL the 'normal' practice would be to just reference the seller in the product entry in the database. With this line of thinking, to load a sellers store page the database would have to search through all products in the database to find what comes from a specific seller. When it comes to very large datasets for products could this be a potential bottleneck in performance? Could the specific use case of loading a seller store justify the seller entry in the database having an array of all products that the seller has listed on the site? I hope my question is clear, this is my first project with MERN stack and I'm trying to pick up the correct terminology, please ask questions if something doesn't make sense and I will try to clarify. The code for the 'user' and 'product' models are below: 'user' with the cart as an embedded modelconst mongoose = require('mongoose'); const Schema = mongoose.Schema; let CART = new Schema({ items:{ type: Array }, total: { type: Number }, formattedTotal:{ type:String }, }); let user = new Schema({ user_name: { type: String }, user_email:{ type:String }, user_address: { type:String }, user_phone:{ type: Number }, user_cart:{ type: [CART] }, user_active:{ type:Boolean } }); module.exports = mongoose.model('User', user); 'product' modelconst mongoose = require('mongoose'); const Schema = mongoose.Schema; let product = new Schema({ product_name:{ type:String }, product_description:{ type: String }, product_price:{ type: Number }, product_quantity:{ type: Number }, product_sellerNAME:{ type:String }, product_sellerID:{ type:String }, product_active:{ type: Boolean } }); module.exports = mongoose.model('product', product);
Submitted May 02, 2020 at 01:34AM by notalentnodirection
No comments:
Post a Comment