diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f9d0a15..fd10f509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This changelog documents the changes between release versions. ## [Unreleased] +### Changed + +- Updates MongoDB Rust driver from v2.8 to v3.1.0 ([#124](https://github.com/hasura/ndc-mongodb/pull/124)) + ## [1.4.0] - 2024-11-14 ### Added diff --git a/Cargo.lock b/Cargo.lock index fd7c146a..b6823834 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,7 +403,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.1", + "strsim", ] [[package]] @@ -412,7 +412,7 @@ version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 2.0.66", @@ -546,38 +546,14 @@ dependencies = [ "typenum", ] -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core 0.13.4", - "darling_macro 0.13.4", -] - [[package]] name = "darling" version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" dependencies = [ - "darling_core 0.20.9", - "darling_macro 0.20.9", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.10.0", - "syn 1.0.109", + "darling_core", + "darling_macro", ] [[package]] @@ -590,28 +566,17 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.11.1", + "strsim", "syn 2.0.66", ] -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core 0.13.4", - "quote", - "syn 1.0.109", -] - [[package]] name = "darling_macro" version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ - "darling_core 0.20.9", + "darling_core", "quote", "syn 2.0.66", ] @@ -652,7 +617,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn 1.0.109", ] @@ -719,14 +684,14 @@ dependencies = [ [[package]] name = "enum-as-inner" -version = "0.4.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", ] [[package]] @@ -1041,12 +1006,6 @@ dependencies = [ "http 0.2.12", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -1065,6 +1024,51 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hickory-proto" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07698b8420e2f0d6447a436ba999ec85d8fbf2a398bbd737b82cac4a2e96e512" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28757f23aa75c98f254cf0405e6d8c25b831b32921b050a66692427679b1f243" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hmac" version = "0.12.1" @@ -1176,7 +1180,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.7", + "socket2", "tokio", "tower-service", "tracing", @@ -1257,7 +1261,7 @@ dependencies = [ "http-body 1.0.0", "hyper 1.3.1", "pin-project-lite", - "socket2 0.5.7", + "socket2", "tokio", "tower", "tower-service", @@ -1413,11 +1417,10 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.2.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] @@ -1497,7 +1500,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2 0.5.7", + "socket2", "widestring", "windows-sys 0.48.0", "winreg 0.50.0", @@ -1615,12 +1618,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - [[package]] name = "matchit" version = "0.7.3" @@ -1714,8 +1711,9 @@ dependencies = [ [[package]] name = "mongodb" -version = "2.8.2" -source = "git+https://github.com/hasura/mongo-rust-driver.git?branch=upstream-time-series-fix#5df5e10153b043c3bf93748d53969fa4345b6250" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c857d71f918b38221baf2fdff7207fec9984b4504901544772b1edf0302d669f" dependencies = [ "async-trait", "base64 0.13.1", @@ -1729,10 +1727,13 @@ dependencies = [ "futures-io", "futures-util", "hex", + "hickory-proto", + "hickory-resolver", "hmac", - "lazy_static", "log", "md-5", + "mongodb-internal-macros", + "once_cell", "pbkdf2", "percent-encoding", "rand", @@ -1741,20 +1742,18 @@ dependencies = [ "rustls-pemfile 1.0.4", "serde", "serde_bytes", - "serde_with 1.14.0", + "serde_with", "sha-1", "sha2", - "socket2 0.4.10", + "socket2", "stringprep", - "strsim 0.10.0", + "strsim", "take_mut", "thiserror", "tokio", "tokio-rustls 0.24.1", "tokio-util", "tracing", - "trust-dns-proto", - "trust-dns-resolver", "typed-builder 0.10.0", "uuid", "webpki-roots", @@ -1791,7 +1790,7 @@ dependencies = [ "schemars", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with", "test-helpers", "thiserror", "time", @@ -1855,6 +1854,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "mongodb-internal-macros" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6dbc533e93429a71c44a14c04547ac783b56d3f22e6c4f12b1b994cf93844e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "mongodb-support" version = "1.4.0" @@ -1896,7 +1906,7 @@ dependencies = [ "schemars", "serde", "serde_json", - "serde_with 3.8.1", + "serde_with", "smol_str", ] @@ -1965,7 +1975,7 @@ dependencies = [ "ndc-models", "rand", "reqwest 0.11.27", - "semver 1.0.23", + "semver", "serde", "serde_json", "smol_str", @@ -2665,32 +2675,23 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.23", + "semver", ] [[package]] name = "rustc_version_runtime" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d31b7153270ebf48bf91c65ae5b0c00e749c4cfad505f66530ac74950249582f" +checksum = "2dd18cd2bae1820af0b6ad5e54f4a51d0f3fcc53b05f845675074efcc7af071d" dependencies = [ - "rustc_version 0.2.3", - "semver 0.9.0", + "rustc_version", + "semver", ] [[package]] @@ -2890,27 +2891,12 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.210" @@ -2986,16 +2972,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_with" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" -dependencies = [ - "serde", - "serde_with_macros 1.5.2", -] - [[package]] name = "serde_with" version = "3.8.1" @@ -3010,29 +2986,17 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "serde_with_macros 3.8.1", + "serde_with_macros", "time", ] -[[package]] -name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling 0.13.4", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "serde_with_macros" version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2" dependencies = [ - "darling 0.20.9", + "darling", "proc-macro2", "quote", "syn 2.0.66", @@ -3132,16 +3096,6 @@ dependencies = [ "serde", ] -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.7" @@ -3175,12 +3129,6 @@ dependencies = [ "unicode-properties", ] -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "strsim" version = "0.11.1" @@ -3406,7 +3354,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.7", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -3663,51 +3611,6 @@ dependencies = [ "tracing-serde", ] -[[package]] -name = "trust-dns-proto" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.2.3", - "ipnet", - "lazy_static", - "log", - "rand", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lazy_static", - "log", - "lru-cache", - "parking_lot", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "trust-dns-proto", -] - [[package]] name = "try-lock" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index 1c71a87e..59880fb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,22 +25,12 @@ indexmap = { version = "2", features = [ "serde", ] } # should match the version that ndc-models uses itertools = "^0.12.1" -mongodb = { version = "2.8", features = ["tracing-unstable"] } +mongodb = { version = "^3.1.0", features = ["tracing-unstable"] } schemars = "^0.8.12" serde = { version = "1", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] } ref-cast = "1.0.23" -# Connecting to MongoDB Atlas database with time series collections fails in the -# latest released version of the MongoDB Rust driver. A fix has been merged, but -# it has not been released yet: https://github.com/mongodb/mongo-rust-driver/pull/1077 -# -# We are using a branch of the driver that cherry-picks that fix onto the v2.8.2 -# release. -[patch.crates-io.mongodb] -git = "https://github.com/hasura/mongo-rust-driver.git" -branch = "upstream-time-series-fix" - # Set opt levels according to recommendations in insta documentation [profile.dev.package] insta.opt-level = 3 diff --git a/crates/cli/src/introspection/sampling.rs b/crates/cli/src/introspection/sampling.rs index f027c01b..d557fac1 100644 --- a/crates/cli/src/introspection/sampling.rs +++ b/crates/cli/src/introspection/sampling.rs @@ -28,7 +28,7 @@ pub async fn sample_schema_from_db( ) -> anyhow::Result> { let mut schemas = BTreeMap::new(); let db = state.database(); - let mut collections_cursor = db.list_collections(None, None).await?; + let mut collections_cursor = db.list_collections().await?; while let Some(collection_spec) = collections_cursor.try_next().await? { let collection_name = collection_spec.name; @@ -60,7 +60,8 @@ async fn sample_schema_from_collection( let options = None; let mut cursor = db .collection::(collection_name) - .aggregate(vec![doc! {"$sample": { "size": sample_size }}], options) + .aggregate(vec![doc! {"$sample": { "size": sample_size }}]) + .with_options(options) .await?; let mut collected_object_types = vec![]; let is_collection_type = true; diff --git a/crates/cli/src/introspection/validation_schema.rs b/crates/cli/src/introspection/validation_schema.rs index 78ee7d25..a21a6fc0 100644 --- a/crates/cli/src/introspection/validation_schema.rs +++ b/crates/cli/src/introspection/validation_schema.rs @@ -22,7 +22,7 @@ pub async fn get_metadata_from_validation_schema( state: &ConnectorState, ) -> Result, MongoAgentError> { let db = state.database(); - let mut collections_cursor = db.list_collections(None, None).await?; + let mut collections_cursor = db.list_collections().await?; let mut schemas: Vec> = vec![]; diff --git a/crates/mongodb-agent-common/src/explain.rs b/crates/mongodb-agent-common/src/explain.rs index 4e556521..0b504da4 100644 --- a/crates/mongodb-agent-common/src/explain.rs +++ b/crates/mongodb-agent-common/src/explain.rs @@ -41,7 +41,7 @@ pub async fn explain_query( tracing::debug!(explain_command = %serde_json::to_string(&explain_command).unwrap()); - let explain_result = db.run_command(explain_command, None).await?; + let explain_result = db.run_command(explain_command).await?; let plan = serde_json::to_string_pretty(&explain_result).map_err(MongoAgentError::Serialization)?; diff --git a/crates/mongodb-agent-common/src/mongodb/collection.rs b/crates/mongodb-agent-common/src/mongodb/collection.rs index db759d1d..ea087442 100644 --- a/crates/mongodb-agent-common/src/mongodb/collection.rs +++ b/crates/mongodb-agent-common/src/mongodb/collection.rs @@ -39,13 +39,12 @@ where where Options: Into> + Send + 'static; - async fn find( + async fn find( &self, - filter: Filter, + filter: Document, options: Options, ) -> Result where - Filter: Into> + Send + 'static, Options: Into> + Send + 'static; } @@ -65,18 +64,19 @@ where where Options: Into> + Send + 'static, { - Collection::aggregate(self, pipeline, options).await + Collection::aggregate(self, pipeline) + .with_options(options) + .await } - async fn find( + async fn find( &self, - filter: Filter, + filter: Document, options: Options, ) -> Result where - Filter: Into> + Send + 'static, Options: Into> + Send + 'static, { - Collection::find(self, filter, options).await + Collection::find(self, filter).with_options(options).await } } diff --git a/crates/mongodb-agent-common/src/mongodb/database.rs b/crates/mongodb-agent-common/src/mongodb/database.rs index 16be274b..75181b0e 100644 --- a/crates/mongodb-agent-common/src/mongodb/database.rs +++ b/crates/mongodb-agent-common/src/mongodb/database.rs @@ -55,7 +55,9 @@ impl DatabaseTrait for Database { where Options: Into> + Send + 'static, { - Database::aggregate(self, pipeline, options).await + Database::aggregate(self, pipeline) + .with_options(options) + .await } fn collection(&self, name: &str) -> Self::Collection { diff --git a/crates/mongodb-agent-common/src/procedure/mod.rs b/crates/mongodb-agent-common/src/procedure/mod.rs index e700efa8..aa3079fc 100644 --- a/crates/mongodb-agent-common/src/procedure/mod.rs +++ b/crates/mongodb-agent-common/src/procedure/mod.rs @@ -44,9 +44,14 @@ impl<'a> Procedure<'a> { self, database: Database, ) -> Result<(bson::Document, Type), ProcedureError> { - let selection_criteria = self.selection_criteria.map(Cow::into_owned); let command = interpolate(self.arguments, &self.command)?; - let result = database.run_command(command, selection_criteria).await?; + let run_command = database.run_command(command); + let run_command = if let Some(selection_criteria) = self.selection_criteria { + run_command.selection_criteria(selection_criteria.into_owned()) + } else { + run_command + }; + let result = run_command.await?; Ok((result, self.result_type)) } diff --git a/crates/ndc-query-plan/src/lib.rs b/crates/ndc-query-plan/src/lib.rs index f7b6b1b5..725ba0cd 100644 --- a/crates/ndc-query-plan/src/lib.rs +++ b/crates/ndc-query-plan/src/lib.rs @@ -6,10 +6,9 @@ pub mod vec_set; pub use mutation_plan::*; pub use plan_for_query_request::{ - plan_for_query_request, + plan_for_mutation_request, plan_for_query_request, query_context::QueryContext, query_plan_error::QueryPlanError, - plan_for_mutation_request, type_annotated_field::{type_annotated_field, type_annotated_nested_field}, }; pub use query_plan::*;