MongoDB Data API for insert

Hello Team,

I’m trying to insert document(s) in the collection through Data API (insertOne/insertMany). But each time I’m getting an error

“Failed to insert document: FunctionError: Failed to insert documents: bulk write exception: write errors: [Document failed validation]”

But the same document I’m able to insert through Add Data Functionality (both through JSON file and insert document) . But after inserting the document, when i fetch it through Data API, same data gets failed while insert action through Data API.

Also logs for Data API are not giving details about this error. Is there a way we can check what causing Data API insert errors in logs ?

Thanks
Nikhil

Hi @Nikhil_Chawla,

Can you provide some sample code snippets and steps to reproduce this behaviour?

In addition to that, could you clarify what you mean by “Add Data Functionality”?

Regards,
Jason

Hello @Jason_Tran ,

Add Data Functionality I’m referring to here through the Compass tool. Please see below image for references.

If you see second image, all 28 documents were inserted fine. But when these documents are inserted through Data API insert operation then they get failed because of below error :

“Failed to insert document: FunctionError: Failed to insert documents: bulk write exception: write errors: [Document failed validation]”

Thanks
Nikhil

Thanks for clarifying. Do you have the Data API insert operation details you could provide? You can copy and paste the request here whilst redacting any personal or sensitive information.

In addition to that, could you provide the output of db.getCollectionInfos()?

I’m trying to replicate this behaviour but it would be helpful if you can provide some exact steps to try reproduce this. If you are able to share any sample documents as well that you have attempted to insert via the Data API, this would be useful as well.

Look forward to hearing from you.

Regards,
Jason