New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@mastra/mongodb

Package Overview
Dependencies
Maintainers
7
Versions
811
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
This package has malicious versions linked to the ongoing "Mastra AI framework compromise" supply chain attack.

Affected versions:

1.9.3
View campaign page

@mastra/mongodb

MongoDB provider for Mastra - includes vector store capabilities

Source
npmnpm
Version
1.18.6
Version published
Weekly downloads
34K
-29.19%
Maintainers
7
Weekly downloads
 
Created
Source

@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',
});

// Connect to MongoDB
await vectorDB.connect();

// Create a new vector index (collection)
await vectorDB.createIndex({
  indexName: 'my_vectors',
  dimension: 3,
  metric: 'cosine', // or 'euclidean', 'dotproduct'
});

// Upsert vectors
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' }],
});

// Query vectors
const results = await vectorDB.query({
  indexName: 'my_vectors',
  queryVector: [0.1, 0.2, 0.3],
  topK: 10,
  filter: { text: 'doc1' },
  includeVector: false,
});

// Clean up
await vectorDB.disconnect();

Documentation

  • MongoDB integration guide
  • MongoDB vector reference

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.

FAQs

Package last updated on 09 Sep 2026

Related posts