Skip to content

DOCSP-32718: geo index code comments #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions source/code-snippets/indexes/geo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Create a geospatial index

const { MongoClient } = require("mongodb");

// Replace the following with your MongoDB deployment's connection
// string.
// Replace the placeholders with your MongoDB deployment's credentials
const uri =
"mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority";

Expand All @@ -13,12 +14,17 @@ async function run() {
const database = client.db("sample_mflix");
const movies = database.collection("movies");

// Create a 2dsphere index on the "location.geo" field in the "theaters" collection.
/* Create a 2dsphere index on the "location.geo" field in the
"movies" collection */
const result = await movies.createIndex({ "location.geo": "2dsphere" });

// Print the result of the index creation
console.log(`Index created: ${result}`);
// end-idx
} finally {
// Close the connection after the operation completes
await client.close();
}
}
// Run the program and print thrown errors
run().catch(console.dir);