This example shows how to do a CRUD operations in fql by building a simple TODO application. Follow these steps:
- Create a
Todos
collection:
Collection.create({ name: "Todos" })
- Add a new TODO item:
Todos.create({
title: "🛍️ Go Shopping",
completed: false,
})
- Get all TODO items:
Todos.all()
- Update a TODO item by its ID. Make sure to replace the '' with your proper document id.
let todo = Todos.byId("<id>")
todo.update({
completed: true
})
- Delete a TODO item by its ID:
Todos.byId(id).delete()
- Get all completed TODO items:
Todos.where(.completed == true)
- Get all incomplete TODO items:
Todos.where(.completed == false)
- You can also get the first uncompleted todo with the following query
Todos.where(.completed == false).first()