File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
source/code-snippets/connection Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { MongoClient } from "mongodb" ;
2
2
3
3
// start-socks
4
+ // Replace the placeholder with your connection string
4
5
const uri = "<connection string uri>" ;
5
6
7
+ // Replace the placeholders with your SOCKS5 proxy server details
6
8
const socksOptions = {
7
9
proxyHost : "<host>" ,
8
10
proxyPort : 1080 ,
9
11
proxyUsername : "<username>" ,
10
12
proxyPassword : "<password>" ,
11
13
} ;
12
14
15
+ // Create a new client with the proxy server details
13
16
const client = new MongoClient ( uri , socksOptions ) ;
14
17
// end-socks
15
18
19
+ // Retrieve the first document from the MongoDB collection and print it
16
20
async function run ( ) {
17
21
try {
18
22
const db = client . db ( "myDB" ) ;
19
23
const myColl = db . collection ( "myColl" ) ;
20
24
const doc = await myColl . findOne ( { } ) ;
21
25
console . log ( doc ) ;
22
26
} finally {
27
+ // Close the connection after the operation completes
23
28
await client . close ( ) ;
24
29
}
25
30
}
You can’t perform that action at this time.
0 commit comments