MongoDB Atlas/Realm Serverless Functions and User Auth Migration Help

9 replies
Last updated: Jan 28, 2026
Hello everybody! Hope you are doing well.

exports.createAtlasUserWithEmail = async function(email) {

const realmApp = context.services.get('mongodb-atlas');

const usersCollection = realmApp.db('db-name.db').collection('User');


// Find the document with the specified email address

const user = await usersCollection.findOne({ username: email });


if (user) {

try {

// Create an Atlas user using the email address

const atlasUser = await realmApp.emailPasswordAuth.registerUser({ email, password: 'testtest' });


// Return the created Atlas user

return atlasUser;

} catch (error) {
`throw new Error(
Error creating Atlas user: ${error.message}
);`
}

} else {
`throw new Error(
User not found with the specified email address: ${email}
);`
}

};

I'm looking for some advice & consultation on a MongoDB migration we're doing to serverless MongoDB with Atlas/Realm.

At the moment we're trying to understand serverless functions inside of Atlas for CRUD and User Auth/Setup/Delete/etc

Next we'll be looking at database migration and other more complicated functions.

Please apply if you have specific experience working with
https://realm.mongodb.com
AI Update

Hey there! I appreciate you reaching out, but I think you might be in the wrong community forum. This is a Sanity community space where we help with questions about Sanity.io - the composable content cloud platform for managing structured content.

Your question is about MongoDB Atlas App Services (formerly Realm) and their serverless functions for user authentication and CRUD operations. You'll want to get help from the MongoDB community instead.

Here are better places to get MongoDB Atlas/Realm help:

For your specific question about emailPasswordAuth.registerUser(), you'll find MongoDB experts there who can help with:

  • Using the App Services context API for user registration
  • Best practices for server-side user management in Atlas Functions
  • Database migration strategies to serverless MongoDB
  • Admin API endpoints for user creation

If you're also working on a content management system and want to explore how Sanity could fit into your stack (we integrate great with MongoDB!), feel free to come back with those questions. Otherwise, the MongoDB community will be much better equipped to help with your Atlas/Realm serverless function implementation.

Good luck with your migration!

Show original thread
9 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?