Hi, I’m pretty new to mongodb aggregate. I’m trying to get the number of result of games that I have stores by the date the game result was declared, but I would like to be able to includes dates that have no result declared and have result be equal to 0 on those days. Since these dates technically don’t exist, I’ve been been struggle to do this. I was wondering if there was a way to add/create these dates in mongodb aggregate. as i want this result like if my first result stored in database on wednesday then i want result of array with this full week start from monday and end with sunday with dates and if result have on these dates then show result as show result 0 or something else i want data with dates with the bunch of weeks Below, I have included what my schema look like with some sample data i’m attaching a screenshot of display data that i want to display for ease to understand. Want data till current week end. I would really appreciate any help or guidance on how to solve this. Thank you!
var GameResult = new mongoose.Schema(
{
game_id: {
type:mongoose.Schema.Types.ObjectId,
ref:"Games",
default:null
},
result_date: {
type: String,
default:""
},
open_decleare_date: {
type: Date,
default:null
},
close_decleare_date: {
type: Date,
default:null
},
open_number: {
type: String,
default:""
},
close_number: {
type: String,
default:""
},
open_decleare_status: {
type: Number,
default:0
},
close_decleare_status:{
type:Number,
default:0
},
open_result_token: {
type: String,
default:""
},
close_result_token: {
type: String,
default:""
}
},
{
timestamps:true
}
);
Desired or Sample Data
[
{
_id: '',
result_date: '11/04/2022',
game_id:'jhbvjadbhvkajd',
open_number:0,
close_number:0,
},
{
_id: '',
result_date: '12/04/2022',
game_id:'jhbvjadbhvkajd',
open_number:0,
close_number:0,
},
{
_id: '',
result_date: '13/04/2022',\
game_id:'jhbvjadbhvkajd',
open_number:0,
close_number:0,
},
{
_id: 'kjabbfckjadbhfjafbalsjbfhals',
result_date: '14/04/2022',
game_id:'jhbvjadbhvkajd',
open_number:123,
close_number:133,
},
{
_id: 'kjabbfckjadbhfjafbalsjbfhals',
result_date: '15/04/2022',
game_id:'jhbvjadbhvkajd',
open_number:232,
close_number:544,
},
{
_id: 'kjabbfckjadbhfjafbalsjbfhals',
result_date: '16/04/2022',
game_id:'jhbvjadbhvkajd',
open_number:879,
close_number:222,
},
{
_id: 'kjabbfckjadbhfjafbalsjbfhals',
result_date: '17/04/2022',
game_id:'jhbvjadbhvkajd',
open_number:0,
close_number:0,
},
]