File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
source/code-snippets/indexes Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 1+ // Create a geospatial index
2+
13const { MongoClient } = require ( "mongodb" ) ;
24
3- // Replace the following with your MongoDB deployment's connection
4- // string.
5+ // Replace the placeholders with your MongoDB deployment's credentials
56const uri =
67 "mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority" ;
78
@@ -13,12 +14,17 @@ async function run() {
1314 const database = client . db ( "sample_mflix" ) ;
1415 const movies = database . collection ( "movies" ) ;
1516
16- // Create a 2dsphere index on the "location.geo" field in the "theaters" collection.
17+ /* Create a 2dsphere index on the "location.geo" field in the
18+ "movies" collection */
1719 const result = await movies . createIndex ( { "location.geo" : "2dsphere" } ) ;
20+
21+ // Print the result of the index creation
1822 console . log ( `Index created: ${ result } ` ) ;
1923 // end-idx
2024 } finally {
25+ // Close the connection after the operation completes
2126 await client . close ( ) ;
2227 }
2328}
29+ // Run the program and print thrown errors
2430run ( ) . catch ( console . dir ) ;
You can’t perform that action at this time.
0 commit comments