A command-line utility for exporting users and pending users from MongoDB Atlas App Services (formerly Realm).
- Export active and pending users from MongoDB Atlas App Services
- Customize the creation date for pending users
- Support for pagination when fetching large user datasets
- Dry run mode for testing without saving data
- Verbose logging for debugging
- Configurable batch size for processing users
- Output to JSON file or console
- Node.js 16 or higher
- MongoDB Atlas account with App Services application
- API key with appropriate permissions
-
Clone this repository:
git clone https://github.com/yourusername/realm-users-migration.git cd realm-users-migration
-
Install dependencies:
pnpm install
-
Create a
.env
file based on the example:cp .env.example .env
-
Edit the
.env
file with your MongoDB Atlas credentials:USERNAME=your_mongodb_username API_KEY=your_mongodb_api_key GROUP_ID=your_mongodb_group_id APP_ID=your_mongodb_app_id
Build the TypeScript project:
pnpm build
Run the migration script:
pnpm start
Option | Description | Default |
---|---|---|
--dryRun |
Run without saving data | false |
--verbose |
Enable detailed logging | false |
--batchSize |
Number of users to process in each batch | 100 |
--outputFile |
Path to save exported users (saved in output directory) | undefined |
--pendingUserDate |
Date for pending users' createdAt field (YYYY-MM-DD) | 2020-12-01 |
--help , -h |
Show help |
Export users to a JSON file:
pnpm start --outputFile users.json
Run in dry run mode with verbose logging:
pnpm start --dryRun --verbose
Set a custom date for pending users:
pnpm start --pendingUserDate 2023-01-15 --outputFile users.json
The output JSON file has the following structure:
{
"metadata": {
"exportDate": "2025-03-30T12:15:00.000Z",
"groupId": "your_group_id",
"appId": "your_app_id",
"totalUsers": 91,
"totalPendingUsers": 40,
"pendingUserDate": "2020-12-01"
},
"users": [
{
"id": "user_id",
"email": "user@example.com",
"createdAt": 1606857105,
"status": "active"
},
...
],
"pendingUsers": [
{
"id": "pending_user_id",
"email": "pending@example.com",
"status": "pending",
"createdAt": 1606780800
},
...
]
}
src/index.ts
- Main entry point and CLI handlingsrc/atlas.ts
- MongoDB Atlas API functionssrc/utils.ts
- Utility functions for logging
pnpm build
- Build the TypeScript projectpnpm start
- Run the compiled scriptpnpm dev
- Run in development mode with auto-reloadpnpm format
- Format code with Prettierpnpm lint
- Run ESLint
MIT