Docs Menu

Docs HomeNode.js

Run a Command

You can run all raw database operations using the db.command() method. Call the command() method with your command object on an instance of a database for diagnostic and administrative tasks such as fetching server stats or initializing a replica set.

Note

Use the mongo shell for administrative tasks instead of the Node.js driver whenever possible.

You can specify additional options in the options object passed in the second parameter of the command() method. For more information on the options you can pass, see the db.command() API documentation.

Note

You can use this example to connect to an instance of MongoDB and interact with a database that contains sample data. To learn more about connecting to your MongoDB instance and loading a sample dataset, see the Usage Examples guide.

Note

Identical Code Snippets

The JavaScript and TypeScript code snippets above are identical. There are no TypeScript specific features of the driver relevant to this use case.

When you run the preceding command, you should see the following output:

{
db: 'sample_mflix',
collections: 6,
views: 0,
objects: 75620,
...
}
←  Retrieve Distinct Values of a FieldWatch for Changes →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.