MongoDB Schema that I have :
const userTaskSchema = new mongoose.Schema(
{
{...}{..}{...}{..} //Multiple objs above here, I just need help with this userTasks
userTasks: [
// Array of tasks with date
{
task: {
type: String,
required: true,
},
date: {
type: Date,
default: Date.now,
},
done: {
type: Boolean,
default: false,
},
},
],
},
The array of task looks like this : Current output
"userTasks": [
{
"done": true,
"_id": "6059c57339d5590b04cb0fec",
"task": "abc",
"date": "2021-03-23T10:39:47.881Z"
},
{
"done": false,
"_id": "6059c57739d5590b04cb0fed",
"task": "abc",
"date": "2021-03-23T10:39:51.558Z"
},
{
"done": false,
"_id": "6059c57839d5590b04cb0fee",
"task": "abc",
"date": "2021-03-23T10:39:52.528Z"
},
{
"done": false,
"_id": "6059c57939d5590b04cb0fef",
"task": "abc",
"date": "2021-03-23T10:39:53.497Z"
},
{
"done": true,
"_id": "6059c57a39d5590b04cb0ff0",
"task": "abc",
"date": "2021-03-23T10:39:54.323Z"
}
],
My desired output is the array which has only done : false values present, I do not want any done : true
I cannot change the schema, this is what I have to work with.
My desired Output :
"userTasks": [
{
"done": false,
"_id": "6059c57739d5590b04cb0fed",
"task": "abc",
"date": "2021-03-23T10:39:51.558Z"
},
{
"done": false,
"_id": "6059c57839d5590b04cb0fee",
"task": "abc",
"date": "2021-03-23T10:39:52.528Z"
},
{
"done": false,
"_id": "6059c57939d5590b04cb0fef",
"task": "abc",
"date": "2021-03-23T10:39:53.497Z"
},
],
I am unable to find any query to get the desired result. Please Help.