@mastra/mongodb
MongoDB Atlas Search implementation for Mastra, providing vector similarity search and index management using MongoDB Atlas Local or Atlas Cloud.
Installation
npm install @mastra/mongodb
Usage
Vector Store
import { MongoDBVector } from '@mastra/mongodb';
const vectorDB = new MongoDBVector({
id: 'mongodb-vector',
uri: 'mongodb://mongodb:mongodb@localhost:27018/?authSource=admin&directConnection=true',
dbName: 'vector_db',
});
await vectorDB.connect();
await vectorDB.createIndex({
indexName: 'my_vectors',
dimension: 3,
metric: 'cosine',
});
const ids = await vectorDB.upsert({
indexName: 'my_vectors',
vectors: [
[0.1, 0.2, 0.3],
[0.3, 0.4, 0.5],
],
metadata: [{ text: 'doc1' }, { text: 'doc2' }],
});
const results = await vectorDB.query({
indexName: 'my_vectors',
queryVector: [0.1, 0.2, 0.3],
topK: 10,
filter: { text: 'doc1' },
includeVector: false,
});
await vectorDB.disconnect();
Documentation
Changelog
See the package changelog for version history and release notes.
Support
We have an open community Discord. Come and say hello and let us know if you have any questions or need any help getting things running.