@mastra/mongodb 1.0.0-beta.11 → 1.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { saveScorePayloadSchema } from '@mastra/core/evals';
11
11
 
12
12
  // package.json
13
13
  var package_default = {
14
- version: "1.0.0-beta.11"};
14
+ version: "1.0.0-beta.12"};
15
15
  var MongoDBFilterTranslator = class extends BaseFilterTranslator {
16
16
  getSupportedOperators() {
17
17
  return {
@@ -105,7 +105,7 @@ var MongoDBVector = class extends MastraVector {
105
105
  client;
106
106
  db;
107
107
  collections;
108
- embeddingFieldName = "embedding";
108
+ embeddingFieldName;
109
109
  metadataFieldName = "metadata";
110
110
  documentFieldName = "document";
111
111
  collectionForValidation = null;
@@ -114,8 +114,11 @@ var MongoDBVector = class extends MastraVector {
114
114
  euclidean: "euclidean",
115
115
  dotproduct: "dotProduct"
116
116
  };
117
- constructor({ id, uri, dbName, options }) {
117
+ constructor({ id, uri, dbName, options, embeddingFieldPath }) {
118
118
  super({ id });
119
+ if (!uri) {
120
+ throw new Error('MongoDBVector requires a connection string. Provide "uri" in the constructor options.');
121
+ }
119
122
  const client = new MongoClient(uri, {
120
123
  ...options,
121
124
  driverInfo: {
@@ -126,6 +129,7 @@ var MongoDBVector = class extends MastraVector {
126
129
  this.client = client;
127
130
  this.db = this.client.db(dbName);
128
131
  this.collections = /* @__PURE__ */ new Map();
132
+ this.embeddingFieldName = embeddingFieldPath ?? "embedding";
129
133
  }
130
134
  // Public methods
131
135
  async connect() {
@@ -857,11 +861,21 @@ function resolveMongoDBConfig(config) {
857
861
  );
858
862
  }
859
863
  }
864
+ const connectionString = config.uri ?? config.url;
865
+ if (!connectionString) {
866
+ throw new MastraError({
867
+ id: createStorageErrorId("MONGODB", "CONSTRUCTOR", "MISSING_URI"),
868
+ domain: ErrorDomain.STORAGE,
869
+ category: ErrorCategory.USER,
870
+ details: { dbName: config?.dbName },
871
+ text: 'MongoDBStore requires a connection string. Provide "uri" (recommended) or "url" in the constructor options.'
872
+ });
873
+ }
860
874
  try {
861
875
  return MongoDBConnector.fromDatabaseConfig({
862
876
  id: "id" in config ? config.id : "domain",
863
877
  options: config.options,
864
- url: config.url,
878
+ url: connectionString,
865
879
  dbName: config.dbName
866
880
  });
867
881
  } catch (error) {
@@ -870,7 +884,7 @@ function resolveMongoDBConfig(config) {
870
884
  id: createStorageErrorId("MONGODB", "CONSTRUCTOR", "FAILED"),
871
885
  domain: ErrorDomain.STORAGE,
872
886
  category: ErrorCategory.USER,
873
- details: { url: config?.url, dbName: config?.dbName }
887
+ details: { uri: config?.uri ?? "", url: config?.url ?? "", dbName: config?.dbName ?? "" }
874
888
  },
875
889
  error
876
890
  );
@@ -2581,7 +2595,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
2581
2595
  };
2582
2596
  }
2583
2597
  const end = perPageInput === false ? total : start + perPage;
2584
- let cursor = collection.find(query).sort({ createdAt: "desc" }).skip(start);
2598
+ let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
2585
2599
  if (perPageInput !== false) {
2586
2600
  cursor = cursor.limit(perPage);
2587
2601
  }
@@ -2630,7 +2644,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
2630
2644
  };
2631
2645
  }
2632
2646
  const end = perPageInput === false ? total : start + perPage;
2633
- let cursor = collection.find({ runId }).sort({ createdAt: "desc" }).skip(start);
2647
+ let cursor = collection.find({ runId }).sort({ createdAt: -1 }).skip(start);
2634
2648
  if (perPageInput !== false) {
2635
2649
  cursor = cursor.limit(perPage);
2636
2650
  }
@@ -2680,7 +2694,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
2680
2694
  };
2681
2695
  }
2682
2696
  const end = perPageInput === false ? total : start + perPage;
2683
- let cursor = collection.find({ entityId, entityType }).sort({ createdAt: "desc" }).skip(start);
2697
+ let cursor = collection.find({ entityId, entityType }).sort({ createdAt: -1 }).skip(start);
2684
2698
  if (perPageInput !== false) {
2685
2699
  cursor = cursor.limit(perPage);
2686
2700
  }
@@ -2731,7 +2745,7 @@ var ScoresStorageMongoDB = class _ScoresStorageMongoDB extends ScoresStorage {
2731
2745
  };
2732
2746
  }
2733
2747
  const end = perPageInput === false ? total : start + perPage;
2734
- let cursor = collection.find(query).sort({ createdAt: "desc" }).skip(start);
2748
+ let cursor = collection.find(query).sort({ createdAt: -1 }).skip(start);
2735
2749
  if (perPageInput !== false) {
2736
2750
  cursor = cursor.limit(perPage);
2737
2751
  }
@@ -3024,7 +3038,7 @@ var WorkflowsStorageMongoDB = class _WorkflowsStorageMongoDB extends WorkflowsSt
3024
3038
  try {
3025
3039
  parsedSnapshot = typeof row.snapshot === "string" ? safelyParseJSON(row.snapshot) : row.snapshot;
3026
3040
  } catch (e) {
3027
- console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
3041
+ this.logger.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
3028
3042
  }
3029
3043
  }
3030
3044
  return {