Type Parameter | Description |
---|---|
TSchema extends ModelSchema | The document schema type |
TMethods extends Record <string , (this , …args ) => any > | Custom methods that will be added to documents |
new Store<Defined in: src/data/store.ts:76 Creates a new Store instanceTSchema
,TMethods
>(name
,options
):Store
<TSchema
,TMethods
>
Parameter | Type | Description |
---|---|---|
name | string | The collection name in MongoDB |
options | { indexes : IndexDescription []; methods? : TMethods ; schema : TSchema ; } | Store configuration |
options.indexes | IndexDescription [] | MongoDB indexes to create |
options.methods? | TMethods | Custom methods to add to documents |
options.schema | TSchema | Document schema using Modelence schema types |
Store
<TSchema
, TMethods
>
Property | Modifier | Type | Defined in |
---|---|---|---|
Doc | readonly | EnhancedOmit <InferDocumentType <TSchema >, "_id" > & object & TMethods | src/data/store.ts:61 |
aggregate(Defined in: src/data/store.ts:346 Aggregates documents using MongoDB’s aggregation frameworkpipeline
,options?
):AggregationCursor
<Document
>
Parameter | Type | Description |
---|---|---|
pipeline | Document [] | The aggregation pipeline |
options? | AggregateOptions | Optional options |
AggregationCursor
<Document
>
The aggregation cursor
bulkWrite(Defined in: src/data/store.ts:356 Performs a bulk write operation on the collectionoperations
):Promise
<BulkWriteResult
>
Parameter | Type | Description |
---|---|---|
operations | AnyBulkWriteOperation <InferDocumentType <TSchema >>[] | The operations to perform |
Promise
<BulkWriteResult
>
The result of the bulk write operation
countDocuments(Defined in: src/data/store.ts:235 Counts the number of documents that match a queryquery
):Promise
<number
>
Parameter | Type | Description |
---|---|---|
query | Filter <InferDocumentType <TSchema >> | The query to filter documents |
Promise
<number
>
The number of documents that match the query
deleteMany(Defined in: src/data/store.ts:335 Deletes multiple documentsselector
):Promise
<DeleteResult
>
Parameter | Type | Description |
---|---|---|
selector | Filter <InferDocumentType <TSchema >> | The selector to find the documents to delete |
Promise
<DeleteResult
>
The result of the delete operation
deleteOne(Defined in: src/data/store.ts:325 Deletes a single documentselector
):Promise
<DeleteResult
>
Parameter | Type | Description |
---|---|---|
selector | Filter <InferDocumentType <TSchema >> | The selector to find the document to delete |
Promise
<DeleteResult
>
The result of the delete operation
fetch(Defined in: src/data/store.ts:246 Fetches multiple documents, equivalent to Node.js MongoDB driver’squery
,options?
):Promise
<EnhancedOmit
<InferDocumentType
<TSchema
>,"_id"
> &object
&TMethods
[]>
find
and toArray
methods combined.
Parameter | Type | Description |
---|---|---|
query | Filter <InferDocumentType <TSchema >> | The query to filter documents |
options? | { limit? : number ; skip? : number ; sort? : Document ; } | Options |
options.limit? | number | - |
options.skip? | number | - |
options.sort? | Document | - |
Promise
<EnhancedOmit
<InferDocumentType
<TSchema
>, "_id"
> & object
& TMethods
[]>
The documents
findById(Defined in: src/data/store.ts:209 Fetches a single document by its IDid
):Promise
<null
|EnhancedOmit
<InferDocumentType
<TSchema
>,"_id"
> &object
&TMethods
>
Parameter | Type | Description |
---|---|---|
id | string | ObjectId | The ID of the document to find |
Promise
<null
| EnhancedOmit
<InferDocumentType
<TSchema
>, "_id"
> & object
& TMethods
>
The document, or null if not found
findOne(Defined in: src/data/store.ts:168query
,options?
):Promise
<null
|EnhancedOmit
<InferDocumentType
<TSchema
>,"_id"
> &object
&TMethods
>
Parameter | Type |
---|---|
query | Filter <InferDocumentType <TSchema >> |
options? | FindOptions <Document > |
Promise
<null
| EnhancedOmit
<InferDocumentType
<TSchema
>, "_id"
> & object
& TMethods
>
getDatabase(): Db
Defined in: src/data/store.ts:365
Returns the raw MongoDB database instance for advanced operations
Db
The MongoDB database instance
getName(): string
Defined in: src/data/store.ts:93
string
insertMany(Defined in: src/data/store.ts:267 Inserts multiple documentsdocuments
):Promise
<InsertManyResult
<Document
>>
Parameter | Type | Description |
---|---|---|
documents | OptionalUnlessRequiredId <InferDocumentType <TSchema >>[] | The documents to insert |
Promise
<InsertManyResult
<Document
>>
The result of the insert operation
insertOne(Defined in: src/data/store.ts:257 Inserts a single documentdocument
):Promise
<InsertOneResult
<Document
>>
Parameter | Type | Description |
---|---|---|
document | OptionalUnlessRequiredId <InferDocumentType <TSchema >> | The document to insert |
Promise
<InsertOneResult
<Document
>>
The result of the insert operation
rawCollection():Defined in: src/data/store.ts:374 Returns the raw MongoDB collection instance for advanced operationsCollection
<InferDocumentType
<TSchema
>>
Collection
<InferDocumentType
<TSchema
>>
The MongoDB collection instance
renameFrom(Defined in: src/data/store.ts:383 Renames an existing collection to this store’s name, used for migrationsoldName
,options?
):Promise
<void
>
Parameter | Type | Description |
---|---|---|
oldName | string | The previous name of the collection |
options? | { session? : ClientSession ; } | - |
options.session? | ClientSession | - |
Promise
<void
>
requireById(Defined in: src/data/store.ts:221 Fetches a single document by its ID, or throws an error if not foundid
,errorHandler?
):Promise
<EnhancedOmit
<InferDocumentType
<TSchema
>,"_id"
> &object
&TMethods
>
Parameter | Type | Description |
---|---|---|
id | string | ObjectId | The ID of the document to find |
errorHandler? | () => Error | Optional error handler to return a custom error if the document is not found |
Promise
<EnhancedOmit
<InferDocumentType
<TSchema
>, "_id"
> & object
& TMethods
>
The document
requireOne(Defined in: src/data/store.ts:176query
,options?
,errorHandler?
):Promise
<EnhancedOmit
<InferDocumentType
<TSchema
>,"_id"
> &object
&TMethods
>
Parameter | Type |
---|---|
query | Filter <InferDocumentType <TSchema >> |
options? | FindOptions <Document > |
errorHandler? | () => Error |
Promise
<EnhancedOmit
<InferDocumentType
<TSchema
>, "_id"
> & object
& TMethods
>
updateMany(Defined in: src/data/store.ts:300 Updates multiple documentsselector
,update
,options?
):Promise
<UpdateResult
<Document
>>
Parameter | Type | Description |
---|---|---|
selector | Filter <InferDocumentType <TSchema >> | The selector to find the documents to update |
update | UpdateFilter <InferDocumentType <TSchema >> | The MongoDB modifier to apply to the documents |
options? | { session? : ClientSession ; } | - |
options.session? | ClientSession | - |
Promise
<UpdateResult
<Document
>>
The result of the update operation
updateOne(Defined in: src/data/store.ts:278 Updates a single documentselector
,update
):Promise
<UpdateResult
<Document
>>
Parameter | Type | Description |
---|---|---|
selector | string | ObjectId | Filter <InferDocumentType <TSchema >> | The selector to find the document to update |
update | UpdateFilter <InferDocumentType <TSchema >> | The update to apply to the document |
Promise
<UpdateResult
<Document
>>
The result of the update operation
upsertMany(Defined in: src/data/store.ts:315 Updates multiple documents, or inserts them if they don’t existselector
,update
):Promise
<UpdateResult
<Document
>>
Parameter | Type | Description |
---|---|---|
selector | Filter <InferDocumentType <TSchema >> | The selector to find the documents to update |
update | UpdateFilter <InferDocumentType <TSchema >> | The MongoDB modifier to apply to the documents |
Promise
<UpdateResult
<Document
>>
The result of the update operation
upsertOne(Defined in: src/data/store.ts:289 Updates a single document, or inserts it if it doesn’t existselector
,update
):Promise
<UpdateResult
<Document
>>
Parameter | Type | Description |
---|---|---|
selector | string | ObjectId | Filter <InferDocumentType <TSchema >> | The selector to find the document to update |
update | UpdateFilter <InferDocumentType <TSchema >> | The MongoDB modifier to apply to the document |
Promise
<UpdateResult
<Document
>>
The result of the update operation