Skip to content

AWS Glue Notebook Cannot Identify Schema Consistently for MongoDB Atlas Source

0

Our current data source is MongoDB Atlas with a million records in 1 collection. I am currently having difficulties using Glue Notebook as it cannot identify the schema consistently. Sometimes it can identify the correct full schema of the collections, sometimes it misses some of the fields. I already tried adding dynamic_frame.relationalize("root", "/tmp/flattened") to my code which increased the consistency, but it still sometimes fail. Are there any other ways to make the schema identification to be consistent?

asked 2 years ago158 views

1 Answer
1

The inconsistent schema identification you're experiencing with AWS Glue Notebook when connecting to MongoDB Atlas is a known issue that can occur due to various factors. Here are some suggestions to improve consistency in schema detection:

  1. Use DataFrame instead of DynamicFrame: DynamicFrame doesn't use the catalog and infers the schema from the actual data files, which can lead to inconsistencies. Consider converting your DynamicFrame to a DataFrame, which uses the catalog and may provide more consistent results.

  2. Implement error handling: Add error handling and retry logic to your code to account for temporary connection issues or data inconsistencies.

  3. Consider alternative connection methods: Instead of using the AWS Glue connector, try connecting to MongoDB Atlas using a URI string, username, and password. This approach has been reported to be more reliable in some cases.

  4. Update to the latest JDBC connector: Ensure you're using the most recent version of the JDBC connector for MongoDB, as newer versions may have bug fixes and improvements.

  5. Pre-process or flatten data: If possible, consider pre-processing or flattening your MongoDB data before ingesting it into Glue. This can help ensure a more consistent schema.

  6. Use a sample dataset: If feasible, work with a representative sample of your data to define the schema explicitly, then apply it to the full dataset.

  7. Implement schema validation: Add schema validation checks in your Glue job to ensure all expected fields are present before processing the data.

If these solutions don't resolve the issue, you may want to consider alternative ETL tools or approaches that are better suited for handling MongoDB data with complex or variable schemas. Additionally, reporting the issue to AWS support may help in getting a more permanent solution if it's indeed a bug in the Glue connector for MongoDB.

Sources
Schema inconsistency between Glue Data Catalog and Glue ETL Job | AWS re:Post
AWS Glue Connector will not connect to mongoDB Atlas | AWS re:Post
Glue Pyspark with MongoDB - "Partitioning failed... Document does not contain key avgObjSize" | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.