I am using RXDB for the first time and i am a bit of trouble understanding how to add data to a document.
I have a "boards" collection, which i can get with db.boards
;
Boards have "columns" and each column has a "tasks" array.
The relevant parts of the schema look like this:
export const boardSchema = {
properties: {
columns: {
type: "array",
items: {
type: "object",
properties: {
tasks: {
type: "array",
items: {},
},
},
},
},
},
};
I am trying to find a way to add a new task into a board > column > tasks array.
I have tried something like this:
const addTaskToColumn = async (boardId: string, columnId: string, task: Task) => {
try {
const boardsCollection = db.boards;
const board = await boardsCollection.findOne(boardId).exec();
const column = board.columns.filter((column: Column) => column.id === columnId)[0];
return await column.update({
$push: {
tasks: task
}
})
} catch (error) {
console.error("There was an error deleting the column", error);
}
};
But i get the error: there was an error deleting the column. TypeError: column.update is not a function
. Why "deleting" the column?!
i have also tried:
return await column.patch({
tasks: [...column.tasks, task]
})
but it also doesn't work. Error there was an error deleting the column. TypeError: column.patch is not a function
.
Any help will be much appreciated...