Skip to content
Documentation
Count Documents Method

Count Documents YAML Method

The countDoc method allows you to retrieve the total number of entries (documents) in a specific table within your YAML database.

Syntax

db.countDoc(dataname)
  .then((result) => {
    if (result.acknowledged) {
      console.log(result.message); // Log the success message
      console.log("Document count:", result.results); // Log the document count
    } else {
      console.error(result.errorMessage); // Log any error message
    }
  })
  .catch((error) => {
    console.error('An error occurred:', error); // Catch any unexpected errors
  });

Parameters

  • dataname: The name of your YAML database.

Example

Suppose you have a YAML database named your_database.db and a table named users. You want to determine the total number of user records in the users table. Here's how you would use the countDoc method:

const dataname = 'your_database.db'; // Specify the name of your database
 
db.countDoc(dataname)
  .then((result) => {
    if (result.acknowledged) {
      console.log(result.message); // Log the success message
      console.log("Document count:", result.results); // Log the document count
    } else {
      console.error(result.errorMessage); // Log any error message
    }
  })
  .catch((error) => {
    console.error('An error occurred:', error); // Catch any unexpected errors
  });

Feel free to adapt this example to your specific use case! 😊


VERSE.DB. Powered by JEDI Studio.