|
| 1 | +# Poco::MongoDB |
| 2 | + |
| 3 | +C++ client library for MongoDB. Speaks the OP_MSG wire protocol over |
| 4 | +`Poco::Net::StreamSocket` and exposes BSON documents, CRUD operations, |
| 5 | +cursors, indexes, and replica-set topology discovery. |
| 6 | + |
| 7 | +Minimum server version: MongoDB 3.6. Legacy opcodes (`OP_QUERY`, |
| 8 | +`OP_INSERT`, etc.) were removed in 1.14 (GH #4781); only `OP_MSG` and |
| 9 | +`OP_COMPRESSED` are sent on the wire. Servers from 3.6 through 8.x are |
| 10 | +supported at the protocol level. The "Server feature compatibility" section |
| 11 | +below details which features are exposed at the API level. |
| 12 | + |
| 13 | +Replica-set support (SDAM, automatic failover, read preferences, topology |
| 14 | +change notifications) is documented in [README-ReplicaSet.md](README-ReplicaSet.md). |
| 15 | + |
| 16 | +## Quick start |
| 17 | + |
| 18 | +```cpp |
| 19 | +#include "Poco/MongoDB/Connection.h" |
| 20 | +#include "Poco/MongoDB/Database.h" |
| 21 | +#include "Poco/MongoDB/OpMsgMessage.h" |
| 22 | + |
| 23 | +using namespace Poco::MongoDB; |
| 24 | + |
| 25 | +Connection connection("localhost", 27017); |
| 26 | +Database db("test"); |
| 27 | + |
| 28 | +auto request = db.createOpMsgMessage("users"); |
| 29 | +request->setCommandName(OpMsgMessage::CMD_INSERT); |
| 30 | + |
| 31 | +Document::Ptr user = new Document; |
| 32 | +user->add("name", "Alice").add("age", 30); |
| 33 | +request->documents().push_back(user); |
| 34 | + |
| 35 | +OpMsgMessage response; |
| 36 | +connection.sendRequest(*request, response); |
| 37 | +``` |
| 38 | +
|
| 39 | +For `mongodb://` URI connections (including authentication), use the |
| 40 | +`Connection::connect(uri, socketFactory)` overload with a user-provided |
| 41 | +`SocketFactory`. |
| 42 | +
|
| 43 | +## Server feature compatibility |
| 44 | +
|
| 45 | +The tables below list MongoDB 6.0 / 7.0 / 8.0 server features and their |
| 46 | +status in Poco::MongoDB: |
| 47 | +
|
| 48 | +- **Supported**: dedicated API. |
| 49 | +- **Partial**: command-level access via `OpMsgMessage` (caller assembles |
| 50 | + the BSON body); no typed helper. |
| 51 | +- **Missing**: no API and no helper; out of reach without library changes. |
| 52 | +- **Added 1.15.x**: introduced by the patch series that ships this document. |
| 53 | +
|
| 54 | +Any command can be sent via `OpMsgMessage` with a hand-built body, so |
| 55 | +"Missing" means "no typed helper", not "unreachable". |
| 56 | +
|
| 57 | +### A. Driver baseline (pre-6.0 specs) |
| 58 | +
|
| 59 | +Capabilities expected of any modern MongoDB driver. |
| 60 | +
|
| 61 | +| Capability | Status | Notes | |
| 62 | +|---|---|---| |
| 63 | +| Stable API (`apiVersion: "1"`, since 5.0) | Missing | Set `apiVersion` manually on each command. | |
| 64 | +| SCRAM-SHA-256 (server default since 4.0) | Added 1.15.x | New `AUTH_SCRAM_SHA256`; default for `authenticate()`. | |
| 65 | +| SCRAM-SHA-1 | Supported | Pass `AUTH_SCRAM_SHA1` explicitly. | |
| 66 | +| x.509 / PLAIN / GSSAPI / MONGODB-AWS / MONGODB-OIDC | Missing | | |
| 67 | +| TLS / SSL | Partial | Default `SocketFactory` throws for secure; user must supply a `SocketFactory` returning a `Poco::Net::SecureStreamSocket`. | |
| 68 | +| `mongodb://` URI | Supported | | |
| 69 | +| `mongodb+srv://` DNS seedlist | Missing | Resolve the host list out of band. | |
| 70 | +| `tls=` URI option | Added 1.15.x | Alias for the historical `ssl=`. | |
| 71 | +| Retryable reads / writes | Missing | Transient network errors are not retried. | |
| 72 | +| Network compression (`zstd` / `zlib` / `snappy`) | Missing | `OP_COMPRESSED` opcode present; no codec or handshake. | |
| 73 | +| ClientSession, causal consistency, snapshot reads | Missing | No multi-document transactions. | |
| 74 | +
|
| 75 | +### B. MongoDB 6.0 |
| 76 | +
|
| 77 | +| Feature | Status | Notes | |
| 78 | +|---|---|---| |
| 79 | +| OP_MSG-only wire protocol | Supported | Cleaned up in 1.14 (GH #4781). | |
| 80 | +| `$densify`, `$fill`, `$documents`, `$maxN`/`$minN`/`$lastN`/`$topN`/`$bottomN`, `$sortArray` | Partial | Hand-rolled aggregation pipeline. | |
| 81 | +| Change streams (`$changeStream`) with `fullDocumentBeforeChange` and DDL events | Missing | No `watch()`, no resume tokens. | |
| 82 | +| Clustered collections (`clusteredIndex`) | Partial | Raw `create` command. | |
| 83 | +| Time-series collections; secondary / compound indexes on them | Partial | Raw `create` command; new `createIndex(extraOptions)` covers the index side. | |
| 84 | +| **Partial indexes (`partialFilterExpression`, since 3.2)** | Added 1.15.x | Pass `partialFilterExpression` in the new `extraOptions` overload. | |
| 85 | +| Hidden indexes (since 4.4) | Added 1.15.x | New `INDEX_HIDDEN` flag. | |
| 86 | +| Text / 2dsphere / hashed / wildcard indexes | Partial | Reachable via `extraOptions`; wildcard via `"$**"` field name. | |
| 87 | +| Collation on indexes | Added 1.15.x | Pass `collation` in `extraOptions`. | |
| 88 | +| Queryable Encryption (preview) | Missing | No `ClientEncryption` class. | |
| 89 | +
|
| 90 | +### C. MongoDB 7.0 |
| 91 | +
|
| 92 | +| Feature | Status | Notes | |
| 93 | +|---|---|---| |
| 94 | +| Queryable Encryption (GA) | Missing | No `ClientEncryption` class, no key-vault helper. | |
| 95 | +| MONGODB-OIDC authentication | Missing | | |
| 96 | +| Compound wildcard indexes | Partial | Reachable via `extraOptions` and a `"$**"` field. | |
| 97 | +| `$median`, `$percentile`, `$bitAnd` / `$bitOr` / `$bitXor` / `$bitNot` | Partial | Hand-rolled aggregation pipeline. | |
| 98 | +| `$changeStreamSplitLargeEvent` | Missing | No change-stream helper. | |
| 99 | +| `analyzeShardKey`, `configureQueryAnalyzer` | Partial | Raw admin command. | |
| 100 | +| Time-series delete relaxations | Supported | Transparent on the wire. | |
| 101 | +
|
| 102 | +### D. MongoDB 8.0 |
| 103 | +
|
| 104 | +| Feature | Status | Notes | |
| 105 | +|---|---|---| |
| 106 | +| Cross-collection `bulkWrite` | Missing | Per-collection batched writes already work via `OpMsgMessage`. | |
| 107 | +| Queryable Encryption range queries | Missing | Depends on QE. | |
| 108 | +| `moveCollection`, `unshardCollection`, config-shard transitions | Partial | Raw admin command. | |
| 109 | +| `setQuerySettings`, `removeQuerySettings` | Partial | Raw admin command. | |
| 110 | +| `$convert` to BinData, `$toUUID`, `$toBinData` | Partial | Hand-rolled aggregation pipeline; UUID binary subtype already supported. | |
| 111 | +| Majority write concern oplog optimization | Supported | Server-side only. | |
| 112 | +
|
| 113 | +### E. BSON type coverage |
| 114 | +
|
| 115 | +| Type | TypeId | Status | |
| 116 | +|---|---|---| |
| 117 | +| Double | 0x01 | Supported | |
| 118 | +| String | 0x02 | Supported | |
| 119 | +| Document | 0x03 | Supported | |
| 120 | +| Array | 0x04 | Supported | |
| 121 | +| Binary (incl. UUID subtype 0x04) | 0x05 | Supported | |
| 122 | +| ObjectId | 0x07 | Supported | |
| 123 | +| Boolean | 0x08 | Supported | |
| 124 | +| UTC DateTime | 0x09 | Supported | |
| 125 | +| Null | 0x0A | Supported | |
| 126 | +| Regex | 0x0B | Supported | |
| 127 | +| JavaScript | 0x0D | Supported | |
| 128 | +| Int32 | 0x10 | Supported | |
| 129 | +| Timestamp | 0x11 | Supported | |
| 130 | +| Int64 | 0x12 | Supported | |
| 131 | +| **Decimal128** | 0x13 | Added 1.15.x | |
| 132 | +| **MinKey** | 0xFF | Added 1.15.x | |
| 133 | +| **MaxKey** | 0x7F | Added 1.15.x | |
| 134 | +| Code-with-scope | 0x0F | Missing | |
| 135 | +| DBPointer (deprecated) | 0x0C | Missing | |
| 136 | +| Symbol (deprecated) | 0x0E | Missing | |
| 137 | +
|
| 138 | +### F. Features obsolete in recent MongoDB |
| 139 | +
|
| 140 | +These work against current servers but the listed replacement is preferred. |
| 141 | +Nothing has been removed. |
| 142 | +
|
| 143 | +| Surface | Status | Replacement | |
| 144 | +|---|---|---| |
| 145 | +| `OpMsgMessage::CMD_MAP_REDUCE` | `POCO_DEPRECATED` (server-deprecated since 5.0). | Aggregation pipeline with `$accumulator`, `$function`, `$out`, `$merge`. | |
| 146 | +| `OpMsgMessage::CMD_COUNT` | Outside Stable API v1; `Database::count()` no longer issues it directly. | Aggregation `$count` (used internally by `Database::count()`). | |
| 147 | +| `Database::INDEX_BACKGROUND` | `POCO_DEPRECATED` (server no-op since 4.2). | Drop the flag; index builds are online by default. | |
| 148 | +| `Database::INDEX_SPARSE` | Superseded by `partialFilterExpression` since 3.2. | Pass `partialFilterExpression` in `createIndex(extraOptions)`. | |
| 149 | +| `Database::createIndex(..., int version)` | Explicit `v=1` is incompatible with several modern index types. | Leave at 0; server picks v=2 (default since 3.4). | |
| 150 | +| Connection URI option `ssl=true` | Replaced by `tls=true` (canonical since 4.2). | Either accepted. | |
| 151 | +
|
| 152 | +### Top blockers |
| 153 | +
|
| 154 | +The largest remaining gaps for users targeting MongoDB 6.0 / 7.0 / 8.0: |
| 155 | +
|
| 156 | + 1. `mongodb+srv://` Atlas connection strings. |
| 157 | + 2. Transactions and `ClientSession`. |
| 158 | + 3. Change streams. |
| 159 | + 4. Queryable Encryption. |
| 160 | + 5. MONGODB-OIDC and other modern auth mechanisms. |
| 161 | + 6. Retryable reads / writes. |
| 162 | + 7. Built-in TLS factory. |
| 163 | + 8. Stable API opt-in. |
| 164 | + 9. Cross-collection `bulkWrite` command. |
| 165 | + 10. Aggregation pipeline builder. |
0 commit comments