// Simple query to get users over 25 years old constsimpleConditions: QueryCondition[] = [ { field:"age", operator:">", value:25 } ];
// Advanced query to get users over 25 years old, ordered by desc // Limitations: If you include a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field // So we can't use multiple fields with a range comparison for now. // https://firebase.google.com/docs/firestore/query-data/order-limit-data constadvancedConditions: QueryCondition[] = [ { field:'age', operator:'>', value:25 }, { field:'age', orderDirection:'desc' }, ]
// Query to get users over 25 years old and limit the results to 5 constlimitedConditions: QueryCondition[] = [ { field:"age", operator:">", value:25 }, { limit:5 } ];
asyncfunctionrun() { try { constpath = 'Users';
// Using the simple conditions constusersByAge = awaitquery<User>(db, path, simpleConditions); console.log(`Found ${usersByAge.length} users over 25 years old.`);
// Using the advanced conditions constorderedUsers = awaitquery<User>(db, path, advancedConditions); console.log(`Found ${orderedUsers.length} users over 25 years old, ordered by name.`);
// Using the limited conditions constlimitedUsers = awaitquery<User>(db, path, limitedConditions); console.log(`Found ${limitedUsers.length} users over 25 years old, limited to 5.`);
Queries the specified collection in Firestore based on the provided conditions and returns an array of documents that match the conditions.
Throws
Throws an exception with an error message if an error occurs.
Example