I am working through mongodb database. I have a list of books and I need to do the following statistics logic. When a user reads a book, the reading time is recorded in statistics from the start of reading. I should receive the following object in json format:
{
"startDate": "2020-12-31",
"endDate": "2020-01-05",
"books": [
"507f1f77bcf86cd799439013"
]
}
Please help me to implement this
CodePudding user response:
If you are asking for structure of schema this would be the best way
const YourSchema = new mongoose.Schema({
startDate:Date,
endDate:Date,
books:[{type: mongoose.Types.ObjectId, ref: 'yourBook Collection'}]
})