I'm trying to create tasks collection where every user has his own object and his tasks are divided into different days. Unfortunately when I try to add new task for existing day, mongo duplicates the day object. I use facile-it/mongodb-bundle for Symfony
That's my code:
$collection = $this->mongoConnection->selectCollection(Table::READ_MONGO_USER_TASKS);
if($collection->countDocuments(['user_id' => $userId->toString()]) === 0) {
$this->createUserDocument($collection, $userId);
}
$task = [
'id' => $event->taskId()->toString(),
'title' => $event->title()
];
$collection->updateOne(
[
'user_id' => $userId->toString()
],
[
'$addToSet' => [
'days' => [
'date' => $deadlineDate,
'tasks_list' => [$task]
]
]
]
);
And when there are 2 or more tasks for the same day, I receive something like this: compass view
What should I do to make it work as expected?