You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-14Lines changed: 61 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,7 @@ PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to Mo
28
28
-**PartiQL-based SQL Syntax**: Built on [PartiQL](https://partiql.org/tutorial.html) (SQL for semi-structured data), enabling seamless SQL querying of nested and hierarchical MongoDB documents
29
29
-**Nested Structure Support**: Query and filter deeply nested fields and arrays within MongoDB documents using standard SQL syntax
30
30
-**MongoDB Aggregate Pipeline Support**: Execute native MongoDB aggregation pipelines using SQL-like syntax with `aggregate()` function
cursor.execute("SELECT COUNT(*) AS total FROM users")
308
+
row = cursor.fetchone()
309
+
print(f"Total users: {row[0]}")
310
+
```
311
+
312
+
**Multiple Aggregates**
313
+
314
+
```python
315
+
cursor.execute(
316
+
"SELECT COUNT(*) AS cnt, AVG(price) AS avg_price, MIN(price) AS cheapest, MAX(price) AS priciest FROM products"
317
+
)
318
+
```
319
+
320
+
**Aggregate with WHERE**
321
+
322
+
```python
323
+
cursor.execute("SELECT COUNT(*) AS total FROM users WHERE active = true AND age > 30")
324
+
```
325
+
326
+
**Aggregate with OR Conditions**
327
+
328
+
```python
329
+
cursor.execute("SELECT COUNT(*) AS cnt FROM users WHERE age < 26 OR age > 40")
330
+
```
331
+
332
+
**Note:** Aggregate functions are translated into a MongoDB `aggregate()` pipeline with `$match` (from WHERE), `$group` (with accumulators), and `$project` stages. `COUNT(*)` maps to `{$sum: 1}`, while `SUM`, `AVG`, `MIN`, and `MAX` map to their corresponding MongoDB accumulators (`$sum`, `$avg`, `$min`, `$max`).
333
+
296
334
### MongoDB Aggregate Function
297
335
298
336
PyMongoSQL supports executing native MongoDB aggregation pipelines using SQL-like syntax with the `aggregate()` function. This allows you to leverage MongoDB's powerful aggregation framework while maintaining SQL-style query patterns.
@@ -608,20 +646,24 @@ The table below shows how PyMongoSQL translates SQL operations into MongoDB comm
0 commit comments