Adamite
  • Initial page
  • Server
    • Introduction
    • Database
      • Configuration
      • Using different adapters
        • Memory Adapter
      • Securing your data
        • Securing read operations
    • Functions
      • Invokable Functions
      • Runtime Functions
      • Scheduled Functions
  • SDK
    • Introduction
    • Database
      • Introduction
      • Read a document
      • Read multiple documents
      • Subscribe to changes
      • Create a new document
      • Update an existing document
      • Delete a document
    • Authentication
      • Create a user
      • Log in and log out
      • Get the logged in user
    • Functions
      • Invoke a function
Powered by GitBook
On this page

Was this helpful?

  1. SDK
  2. Database

Read a document

To read a document, you'll need a reference to it. You can directly reference a document by its ID, or you can access the ref property on a snapshot of the document.

const ref = adamite()
  .database()
  .collection("projects")
  .doc("documentId")
const projects = 
  await adamite()
    .database()
    .collection("projects")
    .get();
    
const ref = projects.docs[0].ref;

Once you have a reference to the document, you can get a snapshot of that document by calling the get method.

const snap = await ref.get();

You can access the document's ID using the id property on the snapshot.

const documentId = snap.id;

You can access the document's data using the data property on the snapshot.

const documentData = snap.data;

And finally, you can access a reference to the document using the ref property on the snapshot.

const documentRef = snap.ref;
PreviousIntroductionNextRead multiple documents

Last updated 5 years ago

Was this helpful?