File: commands.txt

package info (click to toggle)
node-mongodb 3.6.4%2B~cs11.13.19-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 76,604 kB
  • sloc: javascript: 138,083; python: 429; sh: 52; makefile: 37
file content (44 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
=================
Database Commands
=================

Database commands allow you to perform a wide range of diagnostic and administrative
tasks with the Node.js driver. For example, the
:manual:`dbStats </reference/command/dbStats/>` command returns
storage statistics for a given database. Use the ``command`` function to access
database commands.

.. code-block:: js

   const { MongoClient } = require('mongodb');
   
   // Connection URL
   const url = 'mongodb://localhost:27017';
   
   // Create a new MongoClient
   const client = new MongoClient(url);
   
   async function main(client) {
     const db = client.db('myproject');
     const results = await db.command({ dbStats: 1 });
     console.log(results);
   }

   // Function to connect to the server and run your code
   async function run() {
     try {
       // Connect the client to the server
       await client.connect();
       console.log('Connected successfully to server');

       await main(client);
     } finally {
       // Ensures that the client will close when you finish/error
       await client.close();
     }
   }

   // Runs your code
   run();

For a complete list of database commands, see the :manual:`manual </reference/command/>` .