Registry / storage / compass-user-model

compass-user-model

JSON →
library2.8.0jsnpmunverified

A MongoDB user model library used internally by MongoDB Compass. Version 2.8.0 provides a schema and data access layer for user-related data, likely integrated with the Compass application's state management. It is part of the mongodb-js ecosystem, with releases tied to Compass updates. Features include validation, serialization, and basic CRUD operations for user objects, tailored to Compass authentication workflows.

npm install compass-user-model
INSTALL
IMPORT
SIG · COMPASS-USER-MODEL
C
compass-user-model
storagejavascriptv2.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

UserModel
import { UserModel } from 'compass-user-model'
const UserModel = require('compass-user-model').UserModel
ESM is the expected module system, though CJS may work with default export.
createUser
import { createUser } from 'compass-user-model'
import createUser from 'compass-user-model'
createUser is a named export, not the default.
UserSchema
import { UserSchema } from 'compass-user-model'
Available as a named export for schema validation in TypeScript projects.

Connects to MongoDB, creates a user, and fetches all users using the UserModel and createUser functions.

import { UserModel, createUser } from 'compass-user-model'; import { MongoClient } from 'mongodb'; async function main() { const client = new MongoClient(process.env.MONGODB_URI ?? 'mongodb://localhost:27017'); await client.connect(); const db = client.db('test'); const newUser = await createUser(db, { name: 'Alice', email: 'alice@example.com' }); console.log('Created user:', newUser); const users = await UserModel.find(db, {}); console.log('All users:', users); await client.close(); } main().catch(console.error);
Debug
Known issues
breakingIn version 2.0.0, the API was refactored from class-based to function-based. All previous class methods are deprecated.
fix
Migrate to using named functions like createUser, findUserByEmail instead of new UserModel().create().
affects: <2.0.0
deprecatedThe method `UserModel.findById` is deprecated since v2.5.0 and will be removed in v3.
fix
Use `findUserById` function instead.
affects: >=2.5.0
gotchaThe library expects a MongoDB client connection to be passed explicitly to every function; it does not manage connections internally.
fix
Always pass a valid `db` object as the first argument.
affects: >=2.0.0
gotchaUser email uniqueness is not enforced by the library; it relies on a unique index in MongoDB.
fix
Ensure a unique index on the email field is created in your MongoDB collection.
affects: all
Errors
Common errors & fixes
TypeError: UserModel.create is not a function
Using the class-based API from version <2.0.0 after upgrading to 2.x.
fix
Replace with createUser(db, data) function.
Error: db parameter is required
Calling a function without passing the database object.
fix
Pass the connected database object as the first argument, e.g., createUser(db, userData).
MongoBulkWriteError: E11000 duplicate key error collection: test.users index: email_1 dup key: { email: "..." }
Attempting to create a user with an email that already exists.
fix
Check for existing user with findUserByEmail before creation, or handle the duplicate key error gracefully.
Upgrade
Version history
2.8.0latest on npm
Audit
Dependencies
mongodbrequiredProvides the underlying MongoDB driver for database operations
bsonrequiredUsed for ObjectId serialization and deserialization
Agent activity
12 hits · last 30 days
node
12
Resources
compass-user-model — npm install compass-user-model · libregistry