forked from mongodb/docs-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsot.js
31 lines (25 loc) · 755 Bytes
/
csot.js
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
import { MongoClient } from "mongodb";
const { MongoClient } = require('mongodb');
//start-csot
// Creates a new MongoClient with a client-level timeoutMS configuration
const uri = "<connection string uri>";
const client = new MongoClient(uri, {
// Client-level timeout: 15 seconds
timeoutMS: 15000
});
async function run() {
try {
const db = client.db("test-db");
const coll = db.collection("test-collection");
// Performs a query operation with an operation-level timeoutMS configuration
const docs = await coll.find({},
// Operation-level timeout: 10 seconds
{ timeoutMS: 10000 })
.toArray();
console.log(docs);
} finally {
await client.close();
}
}
run().catch(console.dir);
//end-csot