Example
Type Parameters
Constructors
Constructor
new Store<Defined in: packages/modelence/src/data/store.ts:439 Creates a new Store instanceTSchema,TMethods>(name,options):Store<TSchema,TMethods>
Parameters
Returns
Store<TSchema, TMethods>
Properties
Methods
aggregate()
aggregate(Defined in: packages/modelence/src/data/store.ts:1271 Aggregates documents using MongoDB’s aggregation frameworkpipeline,options?):AggregationCursor<Document>
Parameters
Returns
AggregationCursor<Document>
The aggregation cursor
bulkWrite()
bulkWrite(Defined in: packages/modelence/src/data/store.ts:1281 Performs a bulk write operation on the collectionoperations):Promise<BulkWriteResult>
Parameters
Returns
Promise<BulkWriteResult>
The result of the bulk write operation
countDocuments()
countDocuments(Defined in: packages/modelence/src/data/store.ts:915 Counts the number of documents that match a queryquery):Promise<number>
Parameters
Returns
Promise<number>
The number of documents that match the query
create()
create(Defined in: packages/modelence/src/data/store.ts:984 Inserts a single document and returns the inserted document with its generateddocument,options?):Promise<EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
_id
and any helper methods applied.
Unlike insertOne, which only returns the insert result metadata, this method
returns the full inserted document — useful when you need to immediately use the
newly created record (e.g. returning it from an API handler).
Example
Parameters
Returns
Promise<EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The inserted document with _id populated and methods applied
deleteMany()
deleteMany(Defined in: packages/modelence/src/data/store.ts:1100 Deletes multiple documentsselector,options?):Promise<DeleteResult>
Parameters
Returns
Promise<DeleteResult>
The result of the delete operation
deleteOne()
deleteOne(Defined in: packages/modelence/src/data/store.ts:1087 Deletes a single documentselector,options?):Promise<DeleteResult>
Parameters
Returns
Promise<DeleteResult>
The result of the delete operation
distinct()
distinct<Defined in: packages/modelence/src/data/store.ts:1242 Returns an array of distinct values for a field across the collectionK>(key,filter?,options?):Promise<Flatten<WithId<InferDocumentType<TSchema>>[K]>[]>
Type Parameters
Parameters
Returns
Promise<Flatten<WithId<InferDocumentType<TSchema>>[K]>[]>
An array of distinct values
extend()
extend<Defined in: packages/modelence/src/data/store.ts:542 Extends the store with additional schema fields, indexes, methods, and search indexes. Returns a new Store instance with the extended schema and updated types. Methods from the original store are preserved with updated type signatures.TExtendedSchema,TExtendedMethods>(config):Store<TSchema&TExtendedSchema,PreserveMethodsForExtendedSchema<TMethods,TSchema&TExtendedSchema> &TExtendedMethods>
Example
Type Parameters
Parameters
Returns
Store<TSchema & TExtendedSchema, PreserveMethodsForExtendedSchema<TMethods, TSchema & TExtendedSchema> & TExtendedMethods>
A new Store instance with the extended schema
fetch()
fetch(Defined in: packages/modelence/src/data/store.ts:945 Fetches multiple documents, equivalent to Node.js MongoDB driver’squery,options?):Promise<EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods[]>
find and toArray methods combined.
Example
Parameters
Returns
Promise<EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods[]>
The documents
findById()
findById(Defined in: packages/modelence/src/data/store.ts:887 Fetches a single document by its IDid):Promise<null|EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Parameters
Returns
Promise<null | EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The document, or null if not found
findOne()
findOne(Defined in: packages/modelence/src/data/store.ts:844 Finds a single document matching the queryquery,options?):Promise<null|EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Example
Parameters
Returns
Promise<null | EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The document, or null if not found
findOneAndDelete()
findOneAndDelete(Defined in: packages/modelence/src/data/store.ts:1181 Atomically finds a document and deletes it, returning the deleted documentselector,options?):Promise<null|EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Parameters
Returns
Promise<null | EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The deleted document, or null if not found
findOneAndReplace()
findOneAndReplace(Defined in: packages/modelence/src/data/store.ts:1200 Atomically finds a document and replaces it, returning the documentselector,replacement,options?):Promise<null|EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Parameters
Returns
Promise<null | EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The document (before or after replacement, depending on options), or null if not found
findOneAndUpdate()
findOneAndUpdate(Defined in: packages/modelence/src/data/store.ts:1115 Atomically finds a document and updates it, returning the documentselector,update,options?):Promise<null|EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Parameters
Returns
Promise<null | EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The document (before or after update, depending on options), or null if not found
findOneAndUpsert()
findOneAndUpsert(Defined in: packages/modelence/src/data/store.ts:1154 Atomic find-or-create: runsselector,update,options?):Promise<UpsertResult<EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>>
findOneAndUpdate with upsert and reports,
as isNew, whether the returned document was newly inserted.
The plain findOneAndUpdate deliberately hides result metadata and
returns only the document, so it can’t distinguish an insert from a match.
This method surfaces the driver’s lastErrorObject.upserted flag as
isNew, so callers can branch on create-vs-match without a separate
pre-existence read that would race with concurrent upserts.
upsert defaults to true but is overridable — pass upsert: false to
make this a pure find-and-report (unknown selector → { doc: null, isNew: false }). returnDocument is always 'after' and cannot be overridden.
Example
Parameters
Returns
Promise<UpsertResult<EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>>
{ doc, isNew } — doc is null only when upsert: false and
nothing matched; isNew is true exactly when this call inserted the doc.
getDatabase()
getDatabase(): Db
Defined in: packages/modelence/src/data/store.ts:1290
Returns the raw MongoDB database instance for advanced operations
Returns
Db
The MongoDB database instance
Throws
Error if the store is not provisionedgetIndexCreationMode()
getIndexCreationMode(): IndexCreationMode
Defined in: packages/modelence/src/data/store.ts:467
Returns
IndexCreationMode
getName()
getName(): string
Defined in: packages/modelence/src/data/store.ts:463
Returns
string
insertMany()
insertMany(Defined in: packages/modelence/src/data/store.ts:1004 Inserts multiple documentsdocuments,options?):Promise<InsertManyResult<Document>>
Parameters
Returns
Promise<InsertManyResult<Document>>
The result of the insert operation
insertOne()
insertOne(Defined in: packages/modelence/src/data/store.ts:959 Inserts a single documentdocument,options?):Promise<InsertOneResult<Document>>
Parameters
Returns
Promise<InsertOneResult<Document>>
The result of the insert operation
rawCollection()
rawCollection():Defined in: packages/modelence/src/data/store.ts:1299 Returns the raw MongoDB collection instance for advanced operationsCollection<InferDocumentType<TSchema>>
Returns
Collection<InferDocumentType<TSchema>>
The MongoDB collection instance
Throws
Error if the store is not provisionedrenameFrom()
renameFrom(Defined in: packages/modelence/src/data/store.ts:1308 Renames an existing collection to this store’s name, used for migrationsoldName,options?):Promise<void>
Parameters
Returns
Promise<void>
Throws
Error if the old collection doesn’t exist or if this store’s collection already existsreplaceOne()
replaceOne(Defined in: packages/modelence/src/data/store.ts:1221 Replaces a single documentselector,replacement,options?):Promise<UpdateResult<Document>>
Parameters
Returns
Promise<UpdateResult<Document>>
The result of the replace operation
requireById()
requireById(Defined in: packages/modelence/src/data/store.ts:899 Fetches a single document by its ID, or throws an error if not foundid,errorHandler?):Promise<EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Parameters
Returns
Promise<EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
The document
requireOne()
requireOne(Defined in: packages/modelence/src/data/store.ts:852query,options?,errorHandler?):Promise<EnhancedOmit<InferDocumentType<TSchema>,"_id"> &object&TMethods>
Parameters
Returns
Promise<EnhancedOmit<InferDocumentType<TSchema>, "_id"> & object & TMethods>
updateMany()
updateMany(Defined in: packages/modelence/src/data/store.ts:1051 Updates multiple documentsselector,update,options?):Promise<UpdateResult<Document>>
Parameters
Returns
Promise<UpdateResult<Document>>
The result of the update operation
updateOne()
updateOne(Defined in: packages/modelence/src/data/store.ts:1018 Updates a single documentselector,update,options?):Promise<UpdateResult<Document>>
Parameters
Returns
Promise<UpdateResult<Document>>
The result of the update operation
upsertMany()
upsertMany(Defined in: packages/modelence/src/data/store.ts:1070 Updates multiple documents, or inserts them if they don’t existselector,update,options?):Promise<UpdateResult<Document>>
Parameters
Returns
Promise<UpdateResult<Document>>
The result of the update operation
upsertOne()
upsertOne(Defined in: packages/modelence/src/data/store.ts:1033 Updates a single document, or inserts it if it doesn’t existselector,update,options?):Promise<UpdateResult<Document>>
Parameters
Returns
Promise<UpdateResult<Document>>
The result of the update operation
vectorSearch()
vectorSearch(Defined in: packages/modelence/src/data/store.ts:1353 Performs a vector similarity search using MongoDB Atlas Vector Searchparams):Promise<AggregationCursor<Document>>
Example
Parameters
Returns
Promise<AggregationCursor<Document>>
An aggregation cursor with search results and scores
watch()
watch(Defined in: packages/modelence/src/data/store.ts:1260 Opens a change stream on the collection to watch for real-time changespipeline?,options?):ChangeStream
Parameters
Returns
ChangeStream
A ChangeStream instance
vectorIndex()
Defined in: packages/modelence/src/data/store.ts:1416 Creates a MongoDB Atlas Vector Search index definitionstaticvectorIndex(params):object
Example
Parameters
Returns
object
A search index description object