Skip to content

Commit 6ff416d

Browse files
committed
fix: database documentation
1 parent a9e659a commit 6ff416d

File tree

2 files changed

+88
-78
lines changed

2 files changed

+88
-78
lines changed

docs/database.md

Lines changed: 57 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ Work directly with MongoDB databases, collections, users, roles, and indexes thr
1212
## Important Distinction: Database vs Atlas Management
1313

1414
**Database Commands** (`matlas database`) operate directly on MongoDB databases via connection strings:
15-
- Create database-level users and custom roles directly in MongoDB
15+
- Create and manage custom roles with granular privileges
16+
- Manage databases, collections, and indexes
1617
- Require database connection (direct connection string or Atlas cluster with temp user)
17-
- Support granular, collection-level permissions
18-
- Use MongoDB's native `createUser`, `createRole` commands
18+
- Support collection-level permissions and custom role definitions
1919

2020
**Atlas Commands** (`matlas atlas`) operate via Atlas Admin API:
21-
- Manage Atlas-level database users with built-in roles
22-
- Use Atlas API authentication (API keys)
23-
- Assign built-in MongoDB roles (read, readWrite, dbAdmin, etc.)
24-
- Project-level user management
21+
- **All user management** happens through Atlas API (there is no direct MongoDB user creation)
22+
- Users created via Atlas API automatically propagate to MongoDB databases
23+
- Assign built-in MongoDB roles (read, readWrite, dbAdmin, etc.) and custom roles
24+
- Project-level user management with centralized authentication
2525

26-
Use `database` commands for granular database-specific operations and `atlas` commands for centralized Atlas project management.
26+
**User Management**: All database users must be created through `matlas atlas users` commands. Users created in Atlas automatically become available in MongoDB databases after propagation.
2727

2828

2929

@@ -292,7 +292,7 @@ kind: ApplyDocument
292292
metadata:
293293
name: custom-roles-example
294294
resources:
295-
# Custom database role
295+
# Custom database role (created directly in MongoDB)
296296
- apiVersion: matlas.mongodb.com/v1
297297
kind: DatabaseRole
298298
metadata:
@@ -320,7 +320,8 @@ resources:
320320
- roleName: read
321321
databaseName: myapp
322322

323-
# User that uses the custom role
323+
# Atlas database user that uses the custom role
324+
# Note: All users must be created via Atlas API - they propagate to MongoDB databases
324325
- apiVersion: matlas.mongodb.com/v1
325326
kind: DatabaseUser
326327
metadata:
@@ -375,97 +376,75 @@ matlas database roles delete myCustomRole \
375376
--yes
376377
```
377378

378-
## Database Users
379+
## Database Users (Atlas-Managed)
379380

380-
Manage MongoDB database users directly in databases. These users are created using MongoDB's `createUser` command and can be assigned both built-in roles and custom roles created with `matlas database roles`.
381+
**Important**: In MongoDB Atlas, all database users must be created and managed through the Atlas API. Direct MongoDB `createUser` commands are not supported.
381382

382-
**Note**: These are different from Atlas database users managed via `matlas atlas users`. Database users exist only within specific MongoDB databases, while Atlas users are managed centrally via the Atlas API.
383+
All database user management is handled via `matlas atlas users` commands. Users created through Atlas automatically propagate to MongoDB databases and can access databases according to their assigned roles.
383384

384-
### List database users
385-
```bash
386-
# Using connection string
387-
matlas database users list \
388-
--connection-string "mongodb+srv://user:pass@host/" \
389-
--database myapp
385+
### User Management via Atlas API
390386

391-
# Using Atlas cluster with temporary user (recommended)
392-
matlas database users list \
393-
--cluster my-cluster \
394-
--project-id abc123 \
395-
--database myapp \
396-
--use-temp-user
397-
```
387+
For complete user management documentation, see the [Atlas Commands](/atlas/) documentation. Here are the essential commands:
398388

399-
### Create database user
400389
```bash
401-
# Create user with built-in roles
402-
matlas database users create dbuser \
403-
--cluster my-cluster \
390+
# Create Atlas database user (propagates to MongoDB databases)
391+
matlas atlas users create \
404392
--project-id abc123 \
405-
--database myapp \
406-
--use-temp-user \
393+
--username dbuser \
394+
--database-name admin \
407395
--password "SecurePass123!" \
408396
--roles "readWrite@myapp,read@logs"
409397

410-
# Create user with custom roles and display password
411-
matlas database users create appuser \
412-
--cluster my-cluster \
413-
--project-id abc123 \
414-
--database myapp \
415-
--use-temp-user \
416-
--password "SecurePass123!" \
417-
--roles "customRole@myapp" \
418-
--show-password
419-
```
398+
# List all Atlas database users
399+
matlas atlas users list --project-id abc123
420400

421-
### Update database user
422-
```bash
423-
# Update password
424-
matlas database users update dbuser \
425-
--cluster my-cluster \
401+
# Update user roles
402+
matlas atlas users update \
426403
--project-id abc123 \
427-
--database myapp \
428-
--use-temp-user \
429-
--password "NewPass123!"
430-
431-
# Replace all roles
432-
matlas database users update dbuser \
433-
--cluster my-cluster \
434-
--project-id abc123 \
435-
--database myapp \
436-
--use-temp-user \
404+
--username dbuser \
405+
--database-name admin \
437406
--roles "read@myapp,read@logs"
438407

439-
# Add roles incrementally
440-
matlas database users update dbuser \
441-
--cluster my-cluster \
408+
# Get user details
409+
matlas atlas users get \
442410
--project-id abc123 \
443-
--database myapp \
444-
--use-temp-user \
445-
--add-roles "write@logs"
446-
```
411+
--username dbuser \
412+
--database-name admin
447413

448-
### Get database user details
449-
```bash
450-
matlas database users get dbuser \
451-
--cluster my-cluster \
414+
# Delete user
415+
matlas atlas users delete \
452416
--project-id abc123 \
453-
--database myapp \
454-
--use-temp-user
417+
--username dbuser \
418+
--database-name admin
455419
```
456420

457-
### Delete database user
421+
### Role Assignment with Custom Roles
422+
423+
Users created via Atlas can be assigned both built-in MongoDB roles and custom roles created with `matlas database roles`:
424+
458425
```bash
459-
matlas database users delete dbuser \
426+
# Create custom role first
427+
matlas database roles create appRole \
460428
--cluster my-cluster \
461429
--project-id abc123 \
462430
--database myapp \
463431
--use-temp-user \
464-
--yes
432+
--privileges "read@myapp,[email protected]"
433+
434+
# Create user with custom role via Atlas
435+
matlas atlas users create \
436+
--project-id abc123 \
437+
--username appuser \
438+
--database-name admin \
439+
--password "SecurePass123!" \
440+
--roles "appRole@myapp,read@admin"
465441
```
466442

467-
**Important Notes:**
468-
- Database users are scoped to specific databases
469-
- When using `--use-temp-user`, the CLI creates a temporary Atlas user with `userAdmin` privileges for user management
470-
- Database users can be assigned custom roles created with `matlas database roles create`
471-
- Use `--verbose` flag to see detailed operation information
443+
### Propagation and Access
444+
445+
- Users created via Atlas API automatically propagate to all clusters in the project
446+
- Role assignments determine which databases and collections the user can access
447+
- Custom roles created with `matlas database roles` can be assigned to Atlas users
448+
- Use `--verbose` with Atlas commands to see detailed operation information
449+
450+
**Note**: The `matlas database users` commands are not functional in Atlas environments and will redirect you to use `matlas atlas users` instead.

tracking/documentation.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,34 @@ This ensures all developers follow the established workspace rules and maintain
6363

6464
---
6565

66+
## [2025-01-27] Database User Management Documentation Correction
67+
68+
**Status**: Completed
69+
**Developer**: Assistant
70+
**Related Issues**: User feedback about incorrect documentation
71+
72+
### Summary
73+
Corrected misleading documentation in `docs/database.md` that incorrectly claimed there were two different types of user management (Atlas vs Database). Fixed to reflect actual implementation where all users are created via Atlas API and propagate to MongoDB databases.
74+
75+
### Tasks
76+
- [x] Correct main distinction section between Atlas and Database commands
77+
- [x] Remove false separation between "Atlas users" and "Database users"
78+
- [x] Rewrite Database Users section to clarify Atlas-managed nature
79+
- [x] Update examples to show correct Atlas user creation patterns
80+
- [x] Add clarifying comments in YAML examples
81+
82+
### Files Modified
83+
- `docs/database.md` - Major revision to Database Users section and command distinction explanation
84+
85+
### Notes
86+
The original documentation incorrectly suggested that `matlas database users` commands would create users directly in MongoDB using `createUser` commands. However, the actual implementation shows:
87+
88+
1. All user management goes through Atlas API (`internal/services/atlas/users.go`)
89+
2. The `cmd/database/users/users.go` commands are stubs that redirect to Atlas commands
90+
3. Tests in `database-operations.sh` correctly use `matlas atlas users create`
91+
4. Users created via Atlas automatically propagate to MongoDB databases
92+
93+
This correction eliminates confusion and aligns documentation with the actual codebase behavior. The user management model is: **Atlas API → User Creation → Propagation to MongoDB Databases**.
94+
95+
---
96+

0 commit comments

Comments
 (0)