
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
@xylabs/mongo
Advanced tools
Base functionality used throughout XYO TypeScript/JavaScript libraries that access Mongo DB
Base functionality used throughout XYO TypeScript/JavaScript libraries that access Mongo DB
Using npm:
npm install {{name}}
Using yarn:
yarn add {{name}}
Using pnpm:
pnpm add {{name}}
Using bun:
bun add {{name}}
See the LICENSE file for license rights and limitations (LGPL-3.0-only).
### .temp-typedoc
### classes
### <a id="BaseMongoSdk"></a>BaseMongoSdk
Provides a typed wrapper around common MongoDB collection operations.
T extends Document
new BaseMongoSdk<T>(config): BaseMongoSdk<T>;
BaseMongoSdk<T>
config: BaseMongoSdkConfig;
The MongoDB SDK configuration for this instance.
get uri(): string;
Returns the MongoDB connection URI, either from the config or constructed from individual credential fields.
string
deleteMany(filter): Promise<DeleteResult>;
Deletes all documents matching the filter.
Filter<T>
The query filter to match documents for deletion
Promise<DeleteResult>
deleteOne(filter): Promise<DeleteResult>;
Deletes the first document matching the filter.
Filter<T>
The query filter to match a document for deletion
Promise<DeleteResult>
find(filter): Promise<FindCursor<WithId<T>>>;
Finds all documents matching the filter and returns a cursor.
Filter<T>
The query filter
Promise<FindCursor<WithId<T>>>
findOne(filter): Promise<WithId<T> | null>;
Finds a single document matching the filter.
Filter<T>
The query filter
Promise<WithId<T> | null>
The matched document, or null if not found
insertMany(items, options?): Promise<InsertManyResult<T>>;
Inserts multiple documents into the collection.
OptionalUnlessRequiredId<T>[]
The documents to insert
BulkWriteOptions
Optional bulk write options
Promise<InsertManyResult<T>>
insertOne(item, options?): Promise<InsertOneResult<T>>;
Inserts a single document into the collection.
OptionalUnlessRequiredId<T>
The document to insert
InsertOneOptions
Optional insert options
Promise<InsertOneResult<T>>
replaceOne(
filter,
item,
options?): Promise<UpdateResult<T>>;
Replaces a single document matching the filter.
Filter<T>
The query filter to match the document
OptionalUnlessRequiredId<T>
The replacement document
ReplaceOptions
Optional replace options
Promise<UpdateResult<T>>
updateOne(filter, fields): Promise<UpdateResult<T>>;
Updates a single document matching the filter without upserting.
Filter<T>
The query filter to match the document
UpdateFilter<T>
The update operations to apply
Promise<UpdateResult<T>>
upsertOne(filter, fields): Promise<UpdateResult<T>>;
Updates a single document matching the filter, inserting it if it does not exist.
Filter<T>
The query filter to match the document
UpdateFilter<T>
The update operations to apply
Promise<UpdateResult<T>>
useCollection<R>(func): Promise<R>;
Executes a callback with access to the configured MongoDB collection.
R
(collection) => R | Promise<R>
A callback receiving the typed collection
Promise<R>
The result of the callback
useMongo<R>(func): Promise<R>;
Executes a callback with a connected MongoClient, handling connection and disconnection.
R
(client) => R | Promise<R>
A callback receiving the connected MongoClient
Promise<R>
The result of the callback
### <a id="MongoClientWrapper"></a>MongoClientWrapper
Manages a shared pool of MongoClient instances, reusing connections by URI.
new MongoClientWrapper(
uri,
maxPoolSize?,
closeDelay?): MongoClientWrapper;
string
number
number
MongoClientWrapper
readonly static clients: Map<string, MongoClientWrapper>;
Global cache of wrapper instances keyed by connection URI.
static get(
uri,
poolSize?,
closeDelay?): MongoClientWrapper;
Gets or creates a cached MongoClientWrapper for the given URI.
string
The MongoDB connection URI
number
Maximum connection pool size
number
Delay in milliseconds before closing idle connections
MongoClientWrapper
A cached or newly created wrapper instance
connect(): Promise<MongoClient>;
Connects to MongoDB and returns the underlying MongoClient.
Promise<MongoClient>
disconnect(): Promise<number>;
Disconnects from MongoDB.
Promise<number>
initiateClose(): Promise<void>;
Initiates a graceful close of the connection.
Promise<void>
### interfaces
### <a id="BaseMongoSdkPrivateConfig"></a>BaseMongoSdkPrivateConfig
Private configuration options for the Mongo SDK containing connection credentials.
optional dbConnectionString?: string;
A full MongoDB connection string, used instead of individual credential fields.
optional dbDomain?: string;
The MongoDB Atlas cluster domain.
optional dbName?: string;
The database name to connect to.
optional dbPassword?: string;
The password for MongoDB authentication.
optional dbUserName?: string;
The username for MongoDB authentication.
### <a id="BaseMongoSdkPublicConfig"></a>BaseMongoSdkPublicConfig
Public configuration options for the Mongo SDK, safe to expose to clients.
optional closeDelay?: number;
Delay in milliseconds before closing idle connections.
collection: string;
The MongoDB collection name to operate on.
optional maxPoolSize?: number;
Maximum number of connections in the connection pool.
### type-aliases
### <a id="BaseMongoSdkConfig"></a>BaseMongoSdkConfig
type BaseMongoSdkConfig = BaseMongoSdkPublicConfig & BaseMongoSdkPrivateConfig;
Combined public and private MongoDB SDK configuration.
FAQs
Base functionality used throughout XYO TypeScript/JavaScript libraries that access Mongo DB
The npm package @xylabs/mongo receives a total of 136 weekly downloads. As such, @xylabs/mongo popularity was classified as not popular.
We found that @xylabs/mongo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.