@mastra/chroma 0.2.12-alpha.4 → 0.2.12-alpha.5
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +8 -0
- package/dist/_tsup-dts-rollup.d.cts +8 -0
- package/dist/_tsup-dts-rollup.d.ts +8 -0
- package/dist/index.cjs +71 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +71 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/vector/prompt.ts +72 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/chroma@0.2.12-alpha.
|
|
2
|
+
> @mastra/chroma@0.2.12-alpha.5 build /home/runner/work/mastra/mastra/stores/chroma
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8119ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/chroma/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8442ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m10.85 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 801ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m10.90 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 800ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @mastra/chroma
|
|
2
2
|
|
|
3
|
+
## 0.2.12-alpha.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5f826d9: Moved vector store specific prompts from @mastra/rag to be exported from the store that the prompt belongs to, ie @mastra/pg
|
|
8
|
+
- Updated dependencies [3e7b69d]
|
|
9
|
+
- @mastra/core@0.9.1-alpha.5
|
|
10
|
+
|
|
3
11
|
## 0.2.12-alpha.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -11,6 +11,14 @@ import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
|
11
11
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
12
12
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
16
|
+
* This prompt helps users construct valid filters for Chroma Vector.
|
|
17
|
+
*/
|
|
18
|
+
declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
19
|
+
export { CHROMA_PROMPT }
|
|
20
|
+
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* Translator for Chroma filter queries.
|
|
16
24
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
|
@@ -11,6 +11,14 @@ import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
|
11
11
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
12
12
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
16
|
+
* This prompt helps users construct valid filters for Chroma Vector.
|
|
17
|
+
*/
|
|
18
|
+
declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
19
|
+
export { CHROMA_PROMPT }
|
|
20
|
+
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* Translator for Chroma filter queries.
|
|
16
24
|
* Maintains MongoDB-compatible syntax while ensuring proper validation
|
package/dist/index.cjs
CHANGED
|
@@ -233,4 +233,75 @@ var ChromaVector = class extends vector.MastraVector {
|
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
+
// src/vector/prompt.ts
|
|
237
|
+
var CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
238
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
239
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
240
|
+
|
|
241
|
+
Basic Comparison Operators:
|
|
242
|
+
- $eq: Exact match (default when using field: value)
|
|
243
|
+
Example: { "category": "electronics" }
|
|
244
|
+
- $ne: Not equal
|
|
245
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
246
|
+
- $gt: Greater than
|
|
247
|
+
Example: { "price": { "$gt": 100 } }
|
|
248
|
+
- $gte: Greater than or equal
|
|
249
|
+
Example: { "price": { "$gte": 100 } }
|
|
250
|
+
- $lt: Less than
|
|
251
|
+
Example: { "price": { "$lt": 100 } }
|
|
252
|
+
- $lte: Less than or equal
|
|
253
|
+
Example: { "price": { "$lte": 100 } }
|
|
254
|
+
|
|
255
|
+
Array Operators:
|
|
256
|
+
- $in: Match any value in array
|
|
257
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
258
|
+
- $nin: Does not match any value in array
|
|
259
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
260
|
+
|
|
261
|
+
Logical Operators:
|
|
262
|
+
- $and: Logical AND
|
|
263
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
264
|
+
- $or: Logical OR
|
|
265
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
266
|
+
|
|
267
|
+
Restrictions:
|
|
268
|
+
- Regex patterns are not supported
|
|
269
|
+
- Element operators are not supported
|
|
270
|
+
- Only $and and $or logical operators are supported
|
|
271
|
+
- Nested fields are supported using dot notation
|
|
272
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
273
|
+
- Empty arrays in $in/$nin will return no results
|
|
274
|
+
- If multiple top-level fields exist, they're wrapped in $and
|
|
275
|
+
- Only logical operators ($and, $or) can be used at the top level
|
|
276
|
+
- All other operators must be used within a field condition
|
|
277
|
+
Valid: { "field": { "$gt": 100 } }
|
|
278
|
+
Valid: { "$and": [...] }
|
|
279
|
+
Invalid: { "$gt": 100 }
|
|
280
|
+
Invalid: { "$in": [...] }
|
|
281
|
+
- Logical operators must contain field conditions, not direct operators
|
|
282
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
283
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
284
|
+
- Logical operators ($and, $or):
|
|
285
|
+
- Can only be used at top level or nested within other logical operators
|
|
286
|
+
- Can not be used on a field level, or be nested inside a field
|
|
287
|
+
- Can not be used inside an operator
|
|
288
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
289
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
290
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
291
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
292
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
293
|
+
|
|
294
|
+
Example Complex Query:
|
|
295
|
+
{
|
|
296
|
+
"$and": [
|
|
297
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
298
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
299
|
+
{ "$or": [
|
|
300
|
+
{ "inStock": true },
|
|
301
|
+
{ "preorder": true }
|
|
302
|
+
]}
|
|
303
|
+
]
|
|
304
|
+
}`;
|
|
305
|
+
|
|
306
|
+
exports.CHROMA_PROMPT = CHROMA_PROMPT;
|
|
236
307
|
exports.ChromaVector = ChromaVector;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -231,4 +231,74 @@ var ChromaVector = class extends MastraVector {
|
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
// src/vector/prompt.ts
|
|
235
|
+
var CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
236
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
237
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
238
|
+
|
|
239
|
+
Basic Comparison Operators:
|
|
240
|
+
- $eq: Exact match (default when using field: value)
|
|
241
|
+
Example: { "category": "electronics" }
|
|
242
|
+
- $ne: Not equal
|
|
243
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
244
|
+
- $gt: Greater than
|
|
245
|
+
Example: { "price": { "$gt": 100 } }
|
|
246
|
+
- $gte: Greater than or equal
|
|
247
|
+
Example: { "price": { "$gte": 100 } }
|
|
248
|
+
- $lt: Less than
|
|
249
|
+
Example: { "price": { "$lt": 100 } }
|
|
250
|
+
- $lte: Less than or equal
|
|
251
|
+
Example: { "price": { "$lte": 100 } }
|
|
252
|
+
|
|
253
|
+
Array Operators:
|
|
254
|
+
- $in: Match any value in array
|
|
255
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
256
|
+
- $nin: Does not match any value in array
|
|
257
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
258
|
+
|
|
259
|
+
Logical Operators:
|
|
260
|
+
- $and: Logical AND
|
|
261
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
262
|
+
- $or: Logical OR
|
|
263
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
264
|
+
|
|
265
|
+
Restrictions:
|
|
266
|
+
- Regex patterns are not supported
|
|
267
|
+
- Element operators are not supported
|
|
268
|
+
- Only $and and $or logical operators are supported
|
|
269
|
+
- Nested fields are supported using dot notation
|
|
270
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
271
|
+
- Empty arrays in $in/$nin will return no results
|
|
272
|
+
- If multiple top-level fields exist, they're wrapped in $and
|
|
273
|
+
- Only logical operators ($and, $or) can be used at the top level
|
|
274
|
+
- All other operators must be used within a field condition
|
|
275
|
+
Valid: { "field": { "$gt": 100 } }
|
|
276
|
+
Valid: { "$and": [...] }
|
|
277
|
+
Invalid: { "$gt": 100 }
|
|
278
|
+
Invalid: { "$in": [...] }
|
|
279
|
+
- Logical operators must contain field conditions, not direct operators
|
|
280
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
281
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
282
|
+
- Logical operators ($and, $or):
|
|
283
|
+
- Can only be used at top level or nested within other logical operators
|
|
284
|
+
- Can not be used on a field level, or be nested inside a field
|
|
285
|
+
- Can not be used inside an operator
|
|
286
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
287
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
288
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
289
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
290
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
291
|
+
|
|
292
|
+
Example Complex Query:
|
|
293
|
+
{
|
|
294
|
+
"$and": [
|
|
295
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
296
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
297
|
+
{ "$or": [
|
|
298
|
+
{ "inStock": true },
|
|
299
|
+
{ "preorder": true }
|
|
300
|
+
]}
|
|
301
|
+
]
|
|
302
|
+
}`;
|
|
303
|
+
|
|
304
|
+
export { CHROMA_PROMPT, ChromaVector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/chroma",
|
|
3
|
-
"version": "0.2.12-alpha.
|
|
3
|
+
"version": "0.2.12-alpha.5",
|
|
4
4
|
"description": "Chroma vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"chromadb": "^2.2.0",
|
|
24
|
-
"@mastra/core": "^0.9.1-alpha.
|
|
24
|
+
"@mastra/core": "^0.9.1-alpha.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
3
|
+
* This prompt helps users construct valid filters for Chroma Vector.
|
|
4
|
+
*/
|
|
5
|
+
export const CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
6
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
8
|
+
|
|
9
|
+
Basic Comparison Operators:
|
|
10
|
+
- $eq: Exact match (default when using field: value)
|
|
11
|
+
Example: { "category": "electronics" }
|
|
12
|
+
- $ne: Not equal
|
|
13
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
14
|
+
- $gt: Greater than
|
|
15
|
+
Example: { "price": { "$gt": 100 } }
|
|
16
|
+
- $gte: Greater than or equal
|
|
17
|
+
Example: { "price": { "$gte": 100 } }
|
|
18
|
+
- $lt: Less than
|
|
19
|
+
Example: { "price": { "$lt": 100 } }
|
|
20
|
+
- $lte: Less than or equal
|
|
21
|
+
Example: { "price": { "$lte": 100 } }
|
|
22
|
+
|
|
23
|
+
Array Operators:
|
|
24
|
+
- $in: Match any value in array
|
|
25
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
26
|
+
- $nin: Does not match any value in array
|
|
27
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
28
|
+
|
|
29
|
+
Logical Operators:
|
|
30
|
+
- $and: Logical AND
|
|
31
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
32
|
+
- $or: Logical OR
|
|
33
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
34
|
+
|
|
35
|
+
Restrictions:
|
|
36
|
+
- Regex patterns are not supported
|
|
37
|
+
- Element operators are not supported
|
|
38
|
+
- Only $and and $or logical operators are supported
|
|
39
|
+
- Nested fields are supported using dot notation
|
|
40
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
41
|
+
- Empty arrays in $in/$nin will return no results
|
|
42
|
+
- If multiple top-level fields exist, they're wrapped in $and
|
|
43
|
+
- Only logical operators ($and, $or) can be used at the top level
|
|
44
|
+
- All other operators must be used within a field condition
|
|
45
|
+
Valid: { "field": { "$gt": 100 } }
|
|
46
|
+
Valid: { "$and": [...] }
|
|
47
|
+
Invalid: { "$gt": 100 }
|
|
48
|
+
Invalid: { "$in": [...] }
|
|
49
|
+
- Logical operators must contain field conditions, not direct operators
|
|
50
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
51
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
52
|
+
- Logical operators ($and, $or):
|
|
53
|
+
- Can only be used at top level or nested within other logical operators
|
|
54
|
+
- Can not be used on a field level, or be nested inside a field
|
|
55
|
+
- Can not be used inside an operator
|
|
56
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
57
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
58
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
59
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
60
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
61
|
+
|
|
62
|
+
Example Complex Query:
|
|
63
|
+
{
|
|
64
|
+
"$and": [
|
|
65
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
66
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
67
|
+
{ "$or": [
|
|
68
|
+
{ "inStock": true },
|
|
69
|
+
{ "preorder": true }
|
|
70
|
+
]}
|
|
71
|
+
]
|
|
72
|
+
}`;
|