Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 928 Bytes

crud-operations.md

File metadata and controls

57 lines (40 loc) · 928 Bytes

CRUD (Create, Read, Update, Delete) Operations

This example shows how to do a CRUD operations in fql by building a simple TODO application. Follow these steps:

  1. Create a Todos collection:
Collection.create({ name: "Todos" })
  1. Add a new TODO item:
Todos.create({
  title: "🛍️ Go Shopping",
  completed: false,
})
  1. Get all TODO items:
Todos.all()
  1. 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
})
  1. Delete a TODO item by its ID:
Todos.byId(id).delete()
  1. Get all completed TODO items:
Todos.where(.completed == true)
  1. Get all incomplete TODO items:
Todos.where(.completed == false)
  1. You can also get the first uncompleted todo with the following query
Todos.where(.completed == false).first()