Query Documents

Mission

Executing queries retrieves lists of documents from a virtual collection.

The Payoff

By completing this module, you will understand how to run basic queries, configure TypeScript compiler generics, and handle argument constraints.

Estimated Time: 3 minutesModules: 3 Concepts

Establish namespace reference

Target the correct collection key using .collection('users').

Execute data load

Trigger the query by invoking .get() at the end of the query reference.
Interactive Code Snippet
typescript
// Fetch all documents inside the "users" collectionconst users = await sdk.collection("users").get();users.forEach((doc) => {  console.log("Document ID:", doc._id);  console.log("Username:", doc.username);});

Declare interface properties

Create standard interfaces describing document fields.

Load typed structures

Pass your interface inside the generic bracket: .get<InterfaceName>().
Interactive Code Snippet

The TypeScript SDK supports generic response typing to validate document structures during compilation.

typescript
interface Product {  _id: string;  name: string;  price: number;}// Fetch typed documentsconst items = await sdk.collection("products").get<Product>();items.forEach((item) => {  // 'item' is fully typed as Product  console.log(item.name, item.price);});
No Direct Arguments Allowed
The `.get()` method takes **no arguments**. If you pass parameters inside the function, the SDK validates this early and throws an error:
[ThinkingDifferently SDK Error] The .get() method takes no arguments. Please use chainable methods like .where() and .limit().

Instead, use chainable query modifiers like `.where()`, `.limit()`, or `.sort()` to modify the query builder before fetching.

Acknowledge the no-argument constraint

Ensure no parameters or options are passed inside the .get() parentheses.

Apply chainable modifications

Utilize query builders like .where() and .limit() beforehand to filters outcomes.