Skip to content

MongoDB - Allow passing in client or at least options #213

@ryanhyma

Description

@ryanhyma

🚀 The feature

I had to create this in order to use it in my application, because I have to set various options with the client:
import { MongoDb } from '@llm-tools/embedjs-mongodb';
import createDebugMessages from 'debug';

class ExtendedMongoDb extends MongoDb {
debug = createDebugMessages('embedjs:vector:ExtendedMongoDb');

constructor({ client, dbName, collectionName }) {
    // Call parent constructor with dummy connection string
    super({ 
        connectionString: 'mongodb://placeholder',
        dbName,
        collectionName
    });
    
    // Override the client
    this.client = client;
}

async init({ dimensions }) {
    this.debug('Using existing database connection');
    
    // Skip connection since we have a client
    const database = this.client.db(this.dbName);
    this.collection = database.collection(this.collectionName);

    // Let parent class handle index creation
    await super.init({ dimensions });
}

}

export default ExtendedMongoDb;

Motivation, pitch

Mongo has two options for creation, const client = new MongoClient(uri, options);
Allow the passing in of options

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions