Start
Quickstart
Get a connection string and run your first queries with the Python and Node.js MongoDB drivers.
On this page
This page connects an existing driver to a FENVIX database. <endpoint> below stands for the host of your database. To find it, open the console, go to Databases, open your database and look at the Connection string card on the Overview tab. It shows the Host, the Port, the Database and the User, and has a button that copies the whole string.
1. Get a connection string#
A connection string uses the MongoDB protocol. Replace the host of your current connection string with the FENVIX endpoint and keep the rest.
# before
mongodb+srv://<user>:<password>@<your-current-host>/acme
# after
mongodb://<user>:<password>@<endpoint>/acmeThe database name in the path (acme here) selects the database. The first request to a sleeping database wakes it.
The connection string the console shows is the full form, with the port and three options. TLS is required.
mongodb://<user>:<password>@<host>:27017/<database>?tls=true&authSource=<database>&authMechanism=SCRAM-SHA-256The user and password are those of a database user, made in the Users tab of the database. A password is shown once, when the user is made; if it is lost, reset it in the same tab.
2. Connect with Python#
Install the driver, then connect, insert and read back.
pip install pymongofrom pymongo import MongoClient
client = MongoClient("mongodb://<user>:<password>@<endpoint>/acme")
db = client["acme"]
db.orders.insert_one({"status": "paid", "total": 42})
print(db.orders.find_one({"status": "paid"}))3. Connect with Node.js#
npm install mongodbimport { MongoClient } from "mongodb";
const client = new MongoClient("mongodb://<user>:<password>@<endpoint>/acme");
await client.connect();
const db = client.db("acme");
await db.collection("orders").insertOne({ status: "paid", total: 42 });
console.log(await db.collection("orders").findOne({ status: "paid" }));
await client.close();4. Query as before#
Aggregations work the same way. This example uses $match and $lookup, both in the supported set listed under Compatibility.
const paid = await db.collection("orders").aggregate([
{ $match: { status: "paid" } },
{ $lookup: { from: "users", localField: "userId", foreignField: "_id", as: "user" } },
]).toArray();