diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b08b9a..f643859f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,13 @@ This changelog documents the changes between release versions. ### Fixed +- Database introspection no longer fails if any individual collection cannot be sampled ([#160](https://github.com/hasura/ndc-mongodb/pull/160)) + ## [1.7.1] - 2025-03-12 ### Added -- Add watch command while initializing metadata (#157) +- Add watch command while initializing metadata ([#157](https://github.com/hasura/ndc-mongodb/pull/157)) ### Changed diff --git a/Cargo.lock b/Cargo.lock index 53b3ca27..5599f1ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1944,6 +1944,7 @@ dependencies = [ "enum-iterator", "futures-util", "googletest 0.13.0", + "indent", "indexmap 2.2.6", "itertools", "json-structural-diff", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index bbe736ce..00125eba 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -17,6 +17,7 @@ anyhow = "1.0.80" clap = { version = "4.5.1", features = ["derive", "env"] } enum-iterator = "^2.0.0" futures-util = "0.3.28" +indent = "^0.1.1" indexmap = { workspace = true } itertools = { workspace = true } json-structural-diff = "^0.2.0" diff --git a/crates/cli/src/introspection/sampling.rs b/crates/cli/src/introspection/sampling.rs index 4018f48c..78df3302 100644 --- a/crates/cli/src/introspection/sampling.rs +++ b/crates/cli/src/introspection/sampling.rs @@ -87,6 +87,14 @@ pub async fn sample_schema_from_db( while let Some(collection_spec) = collections_cursor.try_next().await? { let collection_name = collection_spec.name; + // The `system.*` namespace is reserved for internal use. In some deployments, such as + // MongoDB v6 running on Atlas, aggregate permissions are denied for `system.views` which + // causes introspection to fail. So we skip those collections. + if collection_name.starts_with("system.") { + log_warning!("collection {collection_name} is under the system namespace which is reserved for internal use - skipping"); + continue; + } + let previously_defined_collection = previously_defined_collections.remove(collection_name.as_str()); @@ -96,15 +104,26 @@ pub async fn sample_schema_from_db( .map(|c| c.collection.r#type.clone()) .unwrap_or_else(|| collection_name.clone().into()); - let Some(collection_schema) = sample_schema_from_collection( + let sample_result = match sample_schema_from_collection( &collection_name, collection_type_name.clone(), sample_size, all_schema_nullable, db, ) - .await? - else { + .await + { + Ok(schema) => schema, + Err(err) => { + let indented_error = indent::indent_all_by(2, err.to_string()); + log_warning!( + "an error occurred attempting to sample collection, {collection_name} - skipping\n{indented_error}" + ); + continue; + } + }; + + let Some(collection_schema) = sample_result else { log_warning!("could not find any documents to sample from collection, {collection_name} - skipping"); continue; };