Facing issue with Mongoexport json file "_id" column

I am exporting mongo collection to json format and then loading that data to bigquery table using bq load command.

mongoexport --uri mongo_uri  --collection coll_1 --type json --fields id,createdAt,updatedAt --out data1.csv 

The json row looks like below:

{"_id":{"$oid":"6234234345345234234sdfsf"},"id":1,"createdAt":"2021-05-11 04:15:15","updatedAt":null}

but when i run bq load command in bigquery it gives below error:

Invalid field name "$oid". Fields must contain only letters, numbers, and underscores, start with a letter or underscore, and be at most 300 characters long.

I think if mongoexport json contains {"_id": ObjectId(6234234345345234234sdfsf)} , my issue will be solved.

Is there any way to export json like this? Or any other way to achive this?

Read more here: https://stackoverflow.com/questions/66997679/facing-issue-with-mongoexport-json-file-id-column

Content Attribution

This content was originally published by Joseph D at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: