MongoVectorRepository
Defined in: mongo-vector-repository.ts:26
A MongoRepository<T> that also implements Mantle’s VectorRepository<T> via
MongoDB Atlas Vector Search ($vectorSearch aggregation stage).
Requirements — this is an Atlas feature, not core MongoDB:
- An Atlas cluster (M0 free tier works) running MongoDB 6.0.11+/7.0.2+.
- An Atlas Vector Search index named
vectorIndexNameon this collection, coveringvectorFieldastype: "vector". Fields referenced in afindSimilarwhere clause must be indexed astype: "filter"in the same index.
Every findSimilar result carries the Atlas similarity score as _score —
HIGHER is more similar (score ∈ [0, 1] for cosine/dotProduct). The embedding
field itself is stripped from results.
Register it with VectorRepositoryService to expose POST /<path>/similar
exactly like the Pinecone/Qdrant adapters.
Extends
Section titled “Extends”MongoRepository<T,D>
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
D = Partial<T>
Implements
Section titled “Implements”VectorRepository<T,D>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MongoVectorRepository<
T,D>(app):MongoVectorRepository<T,D>
Defined in: mongo-repository.ts:44
Parameters
Section titled “Parameters”Returns
Section titled “Returns”MongoVectorRepository<T, D>
Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”_session?
Section titled “_session?”
protectedoptional_session?:ClientSession
Defined in: mongo-repository.ts:42
Session bound by withTransaction() — every driver call passes it when set.
Inherited from
Section titled “Inherited from”candidateMultiplier
Section titled “candidateMultiplier”
readonlycandidateMultiplier:number=10
Defined in: mongo-vector-repository.ts:41
ANN candidate pool multiplier: numCandidates = topK * candidateMultiplier
(capped at Atlas’s 10000 limit). Atlas recommends 10–20× for good recall.
Default
Section titled “Default”10client
Section titled “client”
protectedreadonlyclient:MongoClient
Defined in: mongo-repository.ts:22
Inherited from
Section titled “Inherited from”collectionName
Section titled “collectionName”
abstractreadonlycollectionName:string
Defined in: mongo-repository.ts:26
The MongoDB collection name to target.
Inherited from
Section titled “Inherited from”MongoRepository.collectionName
createdAtField
Section titled “createdAtField”
readonlycreatedAtField:string="createdAt"
Defined in: mongo-repository.ts:31
Field written for auto-managed creation timestamps.
Default
Section titled “Default”"createdAt"Inherited from
Section titled “Inherited from”MongoRepository.createdAtField
protectedreadonlydb:Db
Defined in: mongo-repository.ts:23
Inherited from
Section titled “Inherited from”fieldMap
Section titled “fieldMap”
readonlyfieldMap:Record<string,string> ={}
Defined in: mongo-repository.ts:39
Entity-field-to-document-field overrides, for a collection whose field names don’t
match the entity (e.g. a brownfield collection using snake_case). Does not apply to
id — Mongo’s id is always the driver’s _id.
Default
Section titled “Default”{}Inherited from
Section titled “Inherited from”timestamps
Section titled “timestamps”
readonlytimestamps:boolean=true
Defined in: mongo-repository.ts:29
When true, writes maintain createdAt/updatedAt as BSON Date fields.
Default
Section titled “Default”trueInherited from
Section titled “Inherited from”updatedAtField
Section titled “updatedAtField”
readonlyupdatedAtField:string="updatedAt"
Defined in: mongo-repository.ts:33
Field written for auto-managed update timestamps.
Default
Section titled “Default”"updatedAt"Inherited from
Section titled “Inherited from”MongoRepository.updatedAtField
vectorField
Section titled “vectorField”
readonlyvectorField:string="embedding"
Defined in: mongo-vector-repository.ts:34
Document field storing the embedding.
Default
Section titled “Default”"embedding"vectorIndexName
Section titled “vectorIndexName”
readonlyvectorIndexName:string="vector_index"
Defined in: mongo-vector-repository.ts:31
Name of the Atlas Vector Search index on this collection.
Default
Section titled “Default”"vector_index"Accessors
Section titled “Accessors”collection
Section titled “collection”Get Signature
Section titled “Get Signature”get
protectedcollection():Collection<Document>
Defined in: mongo-repository.ts:50
Escape hatch — the underlying driver Collection for native queries ($regex, aggregations, …).
Returns
Section titled “Returns”Collection<Document>
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”count()
Section titled “count()”count(
params?):Promise<number>
Defined in: mongo-repository.ts:172
Parameters
Section titled “Parameters”params?
Section titled “params?”Returns
Section titled “Returns”Promise<number>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”deleteById()
Section titled “deleteById()”deleteById(
id):Promise<T>
Defined in: mongo-repository.ts:161
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”deleteVector()
Section titled “deleteVector()”deleteVector(
id):Promise<T>
Defined in: mongo-vector-repository.ts:102
Delete a vector and its associated record
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T>
Implementation of
Section titled “Implementation of”describe()
Section titled “describe()”describe():
RepositoryCapabilities
Defined in: mongo-repository.ts:54
Optional capability introspection. All
Returns
Section titled “Returns”Mantlejs
Section titled “Mantlejs”adapters implement it; user repositories may omit it.
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”findAll()
Section titled “findAll()”findAll(
params?):Promise<T[]>
Defined in: mongo-repository.ts:66
Parameters
Section titled “Parameters”params?
Section titled “params?”Returns
Section titled “Returns”Promise<T[]>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”findById()
Section titled “findById()”findById(
id):Promise<T|null>
Defined in: mongo-repository.ts:83
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<T | null>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”findSimilar()
Section titled “findSimilar()”findSimilar(
vector,topK,params?):Promise<T&object[]>
Defined in: mongo-vector-repository.ts:46
Top-K nearest neighbours via $vectorSearch. HIGHER _score is more similar.
Parameters
Section titled “Parameters”vector
Section titled “vector”number[]
number
params?
Section titled “params?”Returns
Section titled “Returns”Promise<T & object[]>
Implementation of
Section titled “Implementation of”fromDocument()
Section titled “fromDocument()”
protectedfromDocument(doc):T
Defined in: mongo-repository.ts:238
Map a driver document to the entity shape: _id: ObjectId becomes id: string.
Parameters
Section titled “Parameters”Record<string, unknown>
Returns
Section titled “Returns”T
Inherited from
Section titled “Inherited from”patchById()
Section titled “patchById()”patchById(
id,data):Promise<T>
Defined in: mongo-repository.ts:129
Parameters
Section titled “Parameters”D
Returns
Section titled “Returns”Promise<T>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”save()
Section titled “save()”save(
data):Promise<T>
Defined in: mongo-repository.ts:92
Parameters
Section titled “Parameters”D
Returns
Section titled “Returns”Promise<T>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”saveAll()
Section titled “saveAll()”saveAll(
data):Promise<T[]>
Defined in: mongo-repository.ts:102
Parameters
Section titled “Parameters”D[]
Returns
Section titled “Returns”Promise<T[]>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”sessionOptions()
Section titled “sessionOptions()”
protectedsessionOptions():object
Defined in: mongo-repository.ts:209
Returns
Section titled “Returns”object
session?
Section titled “session?”
optionalsession?:ClientSession
Inherited from
Section titled “Inherited from”MongoRepository.sessionOptions
toDocument()
Section titled “toDocument()”
protectedtoDocument(data,op,now?):Record<string,unknown>
Defined in: mongo-repository.ts:245
Map boundary data to a driver document: id becomes _id, timestamps applied.
Parameters
Section titled “Parameters”Record<string, unknown>
"create" | "update"
Date = ...
Returns
Section titled “Returns”Record<string, unknown>
Inherited from
Section titled “Inherited from”toEntityField()
Section titled “toEntityField()”
protectedtoEntityField(field):string
Defined in: mongo-repository.ts:232
Translates a document field name back to its entity field name — the inverse of toField.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”toField()
Section titled “toField()”
protectedtoField(field):string
Defined in: mongo-repository.ts:227
Translates an entity field name to its document field name (fieldMap override, else identity).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”toObjectId()
Section titled “toObjectId()”
protectedtoObjectId(id):ObjectId
Defined in: mongo-repository.ts:214
Convert a boundary Id to an ObjectId, rejecting malformed ids loudly.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”ObjectId
Inherited from
Section titled “Inherited from”updateById()
Section titled “updateById()”updateById(
id,data):Promise<T>
Defined in: mongo-repository.ts:113
Parameters
Section titled “Parameters”D
Returns
Section titled “Returns”Promise<T>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”upsertVector()
Section titled “upsertVector()”upsertVector(
id,vector,data):Promise<T>
Defined in: mongo-vector-repository.ts:73
Upsert a record with its embedding vector
Parameters
Section titled “Parameters”vector
Section titled “vector”number[]
Partial<T>
Returns
Section titled “Returns”Promise<T>
Implementation of
Section titled “Implementation of”withTransaction()
Section titled “withTransaction()”withTransaction<
R>(fn):Promise<R>
Defined in: mongo-repository.ts:190
Run a block of repository calls inside one MongoDB transaction. Requires the deployment to be a replica set — true for every Atlas cluster including free-tier M0; standalone servers throw the driver’s native error. The callback receives a session-bound copy of this repository; calls on the original instance are NOT part of the transaction.
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”(txRepo) => Promise<R>
Returns
Section titled “Returns”Promise<R>
Inherited from
Section titled “Inherited from”MongoRepository.withTransaction
wrapError()
Section titled “wrapError()”
protectedwrapError(err):Error
Defined in: mongo-repository.ts:263
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”Error