← All procedures

mongo.documents.find

Find documents with pagination and filtering

MCPCLI
Package
@procedures/mongo · README
Path
["mongo","documents","find"]
CLI
mark mongo documents find
MCP tool
mongo.documents.find on the dev-tools server
As data
{"$proc":["mongo","documents","find"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/mongo"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["mongo","documents","find"], {});
console.log(JSON.stringify(result));

From the command line

$ mark mongo documents find

As data, in a program

{ "$proc": ["mongo", "documents", "find"], "input": {} }

Input

FieldTypeRequiredDefaultDescription
collectionstringnoThe collection name. It takes the place of metadata.collection.
databasestringnoThe database name (default: the database of the connection)
queryobjectnoThe filter of the documents (default: all documents)
projectionobjectnoThe fields to give (1) or to leave out (0)
sortobjectnoThe sort order: { field: 1 } ascending, { field: -1 } descending
pageintegernoThe page to give, from 1
limitintegernoThe number of documents on a page

Output

FieldTypeRequiredDefaultDescription
documentsobject[]yesThe documents of the page
paginationobjectyesThe page of the result
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "collection": {
        "description": "The collection name. It takes the place of metadata.collection.",
        "type": "string",
        "minLength": 1
      },
      "database": {
        "description": "The database name (default: the database of the connection)",
        "type": "string",
        "minLength": 1
      },
      "query": {
        "description": "The filter of the documents (default: all documents)",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {}
      },
      "projection": {
        "description": "The fields to give (1) or to leave out (0)",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "anyOf": [
            {
              "type": "number",
              "const": 0
            },
            {
              "type": "number",
              "const": 1
            }
          ]
        }
      },
      "sort": {
        "description": "The sort order: { field: 1 } ascending, { field: -1 } descending",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {}
      },
      "page": {
        "description": "The page to give, from 1",
        "type": "integer",
        "minimum": 1,
        "maximum": 9007199254740991
      },
      "limit": {
        "description": "The number of documents on a page",
        "type": "integer",
        "minimum": 1,
        "maximum": 9007199254740991
      }
    }
  },
  "output": {
    "type": "object",
    "properties": {
      "documents": {
        "type": "array",
        "items": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {}
        },
        "description": "The documents of the page"
      },
      "pagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "number",
            "description": "The page, from 1"
          },
          "limit": {
            "type": "number",
            "description": "The number of documents on a page"
          },
          "total": {
            "type": "number",
            "description": "The number of documents that match"
          },
          "totalPages": {
            "type": "number",
            "description": "The number of pages"
          },
          "hasNext": {
            "type": "boolean",
            "description": "True when a next page exists"
          },
          "hasPrev": {
            "type": "boolean",
            "description": "True when a previous page exists"
          }
        },
        "required": [
          "page",
          "limit",
          "total",
          "totalPages",
          "hasNext",
          "hasPrev"
        ],
        "additionalProperties": {},
        "description": "The page of the result"
      }
    },
    "required": [
      "documents",
      "pagination"
    ],
    "additionalProperties": {}
  }
}