'product validation failed: describtion: Path `describtion` is required., name: Path `name` is required
when open seed page i get "product validation failed: describtion: Path describtion is required., name: Path name is required." instead of "seed opened", how I can fix it?
import nc from 'next-connect'
import product from '../../models/products'
import db from '../../utils/db'
import { products } from '../../utils/data'
const handel = nc()
handel.get(async(req, res)=>{
await db.connect()
await product.deleteMany()
await product.insertMany(products)
await db.disconnect()
res.send({message: "seed opened"})
})
export default handel
const mongoose = require("mongoose");
const schemaProducts = new mongoose.Schema(
{
name: String,
title: String,
price: Number,
description: String,
category: String,
image: String,
rating: {
rate: Number,
count: Number,
},
},
{
timestamps: true,
}
);
const product =
mongoose.models.product || mongoose.model("product", schemaProducts);
export default product;
const mongoose = require('mongoose')
const connection = {}
async function connect(){
if(connection.isConnected){
console.log('already connedcted')
return;
}
if(mongoose.connections.length > 0){
connection.isConnected = mongoose.connections[0].readyState
if(connection.isConnected == 1){
console.log('use previous state')
return
}
await mongoose.disconnect()
}
const db = await mongoose.connect("mongodb://localhost:27017/store",{
useNewUrlParser : true,
useUnifiedTopology: true,
})
console.log('new connetion')
connection.isConnected = db.connections[0].readyState
}
async function disconnect(){
if(connection.isConnected){
if("mongodb://localhost:27017/store" === 'production'){
await mongoose.disconnect()
connection.isConnected = false
}else{
console.log("not disconnected")
}
}
}
const db = {connect, disconnect}
export default db
export const products = [
{
id: 1,
title: "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops",
price: 109.95,
description: "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
category: "men's clothing",
image: "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
rating: {
rate: 3.9,
count: 120
}
},
{
id: 2,
title: "Mens Casual Premium Slim Fit T-Shirts ",
price: 22.3,
description: "Slim-fitting style, contrast raglan long sleeve, three-button henley placket, light weight & soft fabric for breathable and comfortable wearing. And Solid stitched shirts with round neck made for durability and a great fit for casual fashion wear and diehard baseball fans. The Henley style round neckline includes a three-button placket.",
category: "men's clothing",
image: "https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY._UY_.jpg",
rating: {
rate: 4.1,
count: 259
}
}
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
