Appwrite Database Tutorial #4 - Fetching Documents

Net Ninja · Beginner ·🔧 Backend Engineering ·1y ago

Key Takeaways

The video demonstrates how to fetch documents from an Appwrite database and display them in a browser, using the Appwrite backend-as-a-service platform and its database, authentication, and storage services. The tutorial covers creating an action to fetch all notes from the database, invoking the action from a page component, and passing the notes as a prop to a note list component.

Full Transcript

okay so in the last lesson we added the functionality to create new notes in the database and what I did after the lesson was complete was just go ahead and add a couple more so that we've got a bit more data to work with in this lesson so now what I'd like to do is be able to fetch all of these things and show them in the browser okay then so we want to list out all of the note documents from the database inside the note list components and that component takes in a prop called initial notes which is a list of note objects and we have this bit State set up called notes and the initial value of that state is just the initial notes prop that we Tak in so we actually render this noteless component inside the homepage component right and we pass those initial notes in as a prop right here but right now it's just an empty array so now we're going to create an action to fetch all the notes from the database and then invoke the action from this page component then we can take those notes and pass them in as the prop value so we're going to make this action inside the notes action file again right beneath the ADD no action so to do this we can say export async function we're going to call this one get notes now as a return value it's going to be a promise again which is going to resolve this time to an array of note objects because we'll have multiple notes okay then so inside this function we want to fetch all the documents for the notes collection and to do this this we're going to be using a method on the databases value which we imported from the app setup file so let's say const response is equal to a weit and then it's databases and we use a method on that called list documents we need to also pass in two arguments into this method the database ID as a string which is Notes app remember and then also the collection ID as a string which is just not notes so then this method list documents it grabs all of the documents inside this collection within this database and it returns that whole collection of documents for us inside an array which we can then access through a documents property on this response object that we get back so let's just quickly log those documents out to the console so that we can see them later when we invoke this action now if we wanted to we could just return all those documents directly but they contain a bunch of properties I'm not really interested in for the sake of this project and instead I want to return an array of note objects as defined by the note interface which just contains three properties the content the ID and the created app properties and remember the ID and the created app properties start with a dollar sign because they're generated by app right so we could map the array of documents into a new array of note objects and then return that value to do this we can say const notes which is of type note array and we say that that is equal to response which is the response object dot documents to access the array of documents and then we're going to use the map method on this now the map method FES a function for each item in this documents array and for each item we can return a new No Object which then gets stored in the notes array we're creating so let's add this function and let's take in the current documents as an argument for each iteration and then we want to return a new object inside parentheses for each documents now this object just needs those three properties first of all the ID property which we call dollar sign ID and then we'll set that equal to current doc. ID so this Doc is the argument we take you remember then we need to have a created app property with a dollar sign in front of it which is equal to Doc and then dollar sign created at and finally we need the content property which is equal to doc. content and there's no dollar sign on that one because we created that remember not ight all right and then finally we can just return this notes array so that when we invoke this action we're then returning the full list of notes right then so now we just need to go back to the homepage and we need to invoke that action and all we need to to do is set the notes equal to the action because it returns all the notes for us so we'll say get note so I'm going to click on this to make sure it gets imported up here at the top and we need to invoke this as well all right so we need to also put a wait right here because this is an asynchronous function okay then so let's try this out in the browser all right so now when you view this in a browser and you might have to refresh by the way you should see all of those three documents listed on the homepage awesome so that's working we're fetching all those documents now notice this um if I add a new document then we don't see that new document right here it is still getting added to the database but in order to see it right here we have to refresh the page because we're only fetching those documents when the component first loads in the browser okay now we will address that later on by looking at app right's real time capabilities but for now remember if you add a new note you'll need to refresh the page in order to see that

Original Description

Appwrite is a backend-as-a-service platform, that provides database, authentication, storage, cloud functions and other services. In this Appwrite tutorial, we'll be exploring how to set up and use an Appwrite database. 🔥🥷🏼Sign up to Appwrite for free here - https://apwr.dev/netninja50 🧠🥷🏼Appwrite docs - https://appwrite.io/docs 📂🥷🏼 Access the course files on GitHub: https://github.com/iamshaunjp/appwrite-tutorial 📂🥷🏼 Starter project on GitHub: https://github.com/iamshaunjp/appwrite-tutorial/tree/starter-project
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

This video teaches how to fetch documents from an Appwrite database and display them in a browser. It covers creating an action to fetch all notes from the database and invoking the action from a page component. The tutorial uses the Appwrite backend-as-a-service platform and its database, authentication, and storage services.

Key Takeaways
  1. Create a new action to fetch all notes from the database
  2. Invoke the action from a page component
  3. Pass the notes as a prop to a note list component
  4. Use the list documents method to fetch all documents from the database
  5. Map the array of documents to a new array of note objects
  6. Return the array of note objects
💡 To fetch documents from an Appwrite database, you need to create an action that uses the list documents method and then invoke the action from a page component.

Related Reads

Up next
Indian Express Editorial Analysis by Chandan Sharma - 1 JULY 2026 | UPSC Current Affairs 2026
StudyIQ IAS
Watch →