Answer the question
In order to leave comments, you need to log in
How to add an element to an array field?
Hello everyone! I have such a scheme (yes, yes, I'm a govnokoder).
const bookSchema = new Schema({
title: {
type: String,
required: true
},
author: {
type: String,
require: true,
},
description: {
type: String,
},
img: {
type: String
},
genre: {
type: [String]
},
price: {
type: Number,
required: true
},
rating: {
type: Number,
default: 1,
},
comments: [
{
username: {
type: String
},
comment: {
type: String,
minLength: 2,
maxLength: 1000
},
createdAt: {
type: Date,
default: Date.now()
}
}
]
})
async addComment(req, res) {
///:id/comments/:username
let id = req.params.id
let name = req.params.name
let comment = req.body.comment
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question