Cursor Methods: Size

Returning the number of documents in a collection query.

🪶 The size method returns the number of documents that matched a given query.

1
  • import
  • MerlinDB,
  • {
  • Schema
  • }
  • from
  • "@chrisaxxwell/merlin-db";
    2
  • //Or if you are using 'merlindb.max.js' just call 'new MerlinDB()';
  • 3
    4
  • const
  • merlin =
  • new
  • MerlinDB(
  • )
  • ;
    5merlin
  • .connect(
  • "USER-DATABASE"
  • )
  • ;  
    6
  • var
  • userModel = merlin
  • .model(
  • "User", <userSchema>
  • )
  • ;
    7
    8
  • //cursor.size();
  • 9userModel
  • .find(
  • {
  • age:
  • 23
  • }
  • )
  • .size(
  • )
  • .then(
  • e =>
  • {
  • 10   console
  • .log(
  • e
  • )
  • ;
    11  
  • //returns 3
  • 12
  • }
  • )