Answer the question
In order to leave comments, you need to log in
How to correctly group by date an array property (comments) in MogoDb?
Good afternoon. I am doing a simple cms on the mean stack, the lack of long experience in Mondo and NoSQL brought me to a small stupor.
There is a collection of articles in which comments are stored as a separate property in the form of an array.
Here is his description.
comments: [{
message: String,
postedBy: {type: Schema.Types.ObjectId, ref: 'User'},
createdDate: {type: Date, default: Date.now, required: true} }]
.populate('comments')
Answer the question
In order to leave comments, you need to log in
Use aggregation and grouping by year, month, day.
https://docs.mongodb.com/manual/reference/operator...
Your pipeline will include an $unwind operator that will break up comments.
Then group them by date with the union via $addToSet .
Install Robomongo and watch YouTube about aggregation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question