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 11import { MongoClient } from "mongodb" ;
22
33// start-socks
4+ // Replace the placeholder with your connection string
45const uri = "<connection string uri>" ;
56
7+ // Replace the placeholders with your SOCKS5 proxy server details
68const socksOptions = {
79 proxyHost : "<host>" ,
810 proxyPort : 1080 ,
911 proxyUsername : "<username>" ,
1012 proxyPassword : "<password>" ,
1113} ;
1214
15+ // Create a new client with the proxy server details
1316const client = new MongoClient ( uri , socksOptions ) ;
1417// end-socks
1518
19+ // Retrieve the first document from the MongoDB collection and print it
1620async function run ( ) {
1721 try {
1822 const db = client . db ( "myDB" ) ;
1923 const myColl = db . collection ( "myColl" ) ;
2024 const doc = await myColl . findOne ( { } ) ;
2125 console . log ( doc ) ;
2226 } finally {
27+ // Close the connection after the operation completes
2328 await client . close ( ) ;
2429 }
2530}
You can’t perform that action at this time.
0 commit comments