Home:ALL Converter>How to find the count of documents containing null values in MongoDB?

How to find the count of documents containing null values in MongoDB?

Ask Time:2020-04-15T20:50:29         Author:Salih

Json Formatter

I have gone thorough the stackoverflow link How to find null documents in mongodb? , but it returns all documents and not just Null. Also, I just need the count and no actions on the Null-containing Documents.

So, the background is, I've imported the collection from MongoDB 4.0.17 to AWS DocumentDB (~Mongo 3.6). I see that are 2000 documents less in the new DocumentDB. Also below is the error message that i received during the restore/import.

2020-04-15T12:31:07.412+0000    [####################....]  prod.original_post  1.65GB/1.96GB  (84.3%)
2020-04-15T12:31:08.347+0000    error: Unsupported BSON : has null character in string
2020-04-15T12:31:10.412+0000    [####################....]  prod.original_post  1.68GB/1.96GB  (85.8%)
2020-04-15T12:31:22.417+0000    [######################..]  prod.original_post  1.81GB/1.96GB  (92.1%)
2020-04-15T12:31:31.602+0000    [########################]  prod.original_post  1.96GB/1.96GB  (100.0%)
2020-04-15T12:31:31.602+0000    restoring indexes for collection prod.original_post from metadata
2020-04-15T12:32:11.687+0000    finished restoring prod.original_post (3700504 documents)
2020-04-15T12:32:11.687+0000    done

And, following the AWS forum https://forums.aws.amazon.com/thread.jspa?messageID=908846 I tried to make sure that the missing documents are due to the Null Values. But unable to take a Null-valued documents' count.

Author:Salih,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61229162/how-to-find-the-count-of-documents-containing-null-values-in-mongodb
meet-bhagdev :

A couple of things - \n\n\nAmazon DocumentDB does not allow the null character (Unicode \\u0000) in string value. That is likely the reason you see 2000 records less in your DocumentDB cluster. The DocumentDB team is however working on adding support for null characters.\n\n\nIn the meanwhile, as suggested in the AWS forum, there are two ways to mitigate this:\n\n\nSearch your source MongoDB collections for strings with a null character, and replace the null character with space/other character/nothing as is appropriate for your use case.\nFor CDC migration, use the appropriate DMS Error Handling Task Setting (https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.CustomizingTasks.TaskSettings.ErrorHandling.html) to log the error and continue, then review the errors and edit/migrate those documents separately.\n\n\nOn how to identify which documents have null values, using Oled's approach makes sense to me.",
2020-04-16T23:41:46
yy