MongoDB
This page shows you how to create a MongoDB user and a database, and how to connect to them from your lab.
1. Create a user
- Go to Services and select Manage on MongoDB.
- Select Add User (or Create User if you have none yet).
- Fill in Username, Password and Confirm Password, then confirm.
| Field | Rules |
|---|---|
| Username | 5–16 characters: letters, digits and underscores. Not only digits, and not a reserved name. |
| Password | At least 8 characters. Single quotes (') are not allowed. |
2. Create a database
- Open the Database tab.
- Choose the Username that will own it.
- Type a Database Name. It is prefixed with the user's name and an
underscore. For example,
notesowned byalice_devbecomesalice_dev_notes. - Select Create Database.
Each user card shows how many databases the user owns and how many it can own. At the limit, you see Database limit exceeded for the user.
3. Get the connection string
MongoDB users sign in against a specific authentication database, and a connection without it is refused. The dashboard gives you a connection string with everything filled in:
- On the Dashboard tab, open the menu on the user's card.
- Choose Show Connection Info.
The dialog shows the Username, Password, Authentication Database and a ready-made Connection String. Copy the string.
4. Connect from your lab
Connect with the string you copied, using mongosh. If mongosh is not in your lab, install it by following MongoDB's own instructions.
mongosh "<connection-string>"
Then switch to your database:
use <user>_notes
db.items.insertOne({ title: "first" })
db.items.find()
From code, use the same connection string and give your database name explicitly. Keep the authentication database parameter that is already in the string.
If you connect from your own computer through VS Code port forwarding, and VS Code forwarded to a different local port, replace the host and port in the string with the forwarded ones.
Managing what you created
| Task | Where |
|---|---|
| Drop a database | Its card on the Database tab |
| Delete a user | Delete User in the card menu — this also deletes every database it owns |
If it does not connect
| Symptom | Check |
|---|---|
| Authentication failed | The authentication database is included. Copy the string from Show Connection Info again. |
| not authorized on … | You are using a database this user owns, with its full prefixed name |
| Connection times out | You are connecting from inside a lab, or through the port forwarding helpers |
Do it with an AI assistant
You can also do this by asking an AI assistant connected to your account — see Connect an AI assistant to set one up.
| Ask | What the assistant does |
|---|---|
| “Create a MongoDB user called appsvc01” | add_service_user |
| “Create a database called orders for it” | create_database |
| “Give me the connection details for appsvc01” | service_credentials |
The user gets access only when a database is created for it. Until then, it can connect, but every read or write is refused. Ask the assistant to create the database in the same request.
Next
- Databases and services — limits and public endpoints
- Redis