import { base44 } from '@/api/base44Client';
base44.entities.Todo.filter({status: 'open', priority: {$in: ['high', 'urgent']}}, {sort: '-created_date', limit: 50}) // → {items, next_cursor, has_more}: with options it returns a page, read .items. Load more: the same call with cursor: page.next_cursor. Operators: $in/$nin/$gt/$gte/$lt/$lte/$ne/$exists/$or, $regex for text search. Same options on list({sort, limit, cursor})
base44.entities.Todo.count({status: 'open'}) // a number: totals, badges, "N of M"
base44.entities.Todo.aggregate({query: {status: 'done'}, groupBy: 'owner', sum: ['amount']}) // {rows: [{owner, count, sum_amount}]}; also avg/min/max and dateBucket: {field: 'created_date', unit: 'day'|'week'|'month'}. One call covers all counters of an entity
base44.entities.Todo.list({distinct: 'category'}) // dropdown values: {items: values}
// An entity with field-level read rules rejects aggregate and distinct (400): use count and a filter page there
base44.entities.Todo.create({title: "Todo 1"})
base44.entities.Todo.bulkCreate([{title: "Todo 2"}, {title: "Todo 3"}])
base44.entities.Todo.update(todo.id, {description: "new"})
base44.entities.Todo.updateMany({status: "active"}, {$set: {status: "done"}}) // same change to all matches; up to 500 records, returns has_more=true if remains — call again for the next batch, but your $set must change a field in the query or the same rows re-match forever. 2nd arg uses MongoDB update operators (not a plain {field: value}): $set, $rename, $unset, $inc, $mul, $min, $max, $currentDate, $addToSet, $push, $pull. careful: no schema validation
base44.entities.Todo.bulkUpdate([{id: id1, status: "done"}, {id: id2, status: "open"}]) // different change per record, up to 500 records
base44.entities.Todo.delete(todo.id)
base44.entities.Todo.deleteMany({status: "archived"}) // deletes all matches in one call. careful: a broad or empty ({}) query deletes everything it's allowed to