I am trying to insert the following list of dictionaries named posts
to mongo, and got a BulkWriteError: batch op errors occurred
error which I don't know how to fix.
posts:
[{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680',
'Records': [
{'DATE': '07/22/09 05:54 PM',
'STATUS': 'Is flying back friday night in time to move the rest of his stuff then go to work the next morning... great.'},
......
{'DATE': '07/19/09 04:39 PM', 'STATUS': 'is stealing his net by the lake'}]},
{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680',
'Records': [
{'DATE': '07/22/09 05:54 PM',
'STATUS': 'Is flying back friday night in time to move the rest of his stuff then go to work the next morning... great.'},
{'DATE': '07/19/09 04:39 PM', 'STATUS': 'is stealing his net by the lake'},
....
The code I used:
collection = db.posts
collection.insert_many(p for p in posts )
But then I got an error that says BulkWriteError: batch op errors occurred
and only managed to import the first dictionary (corresponding to the first #AUTHID
)
I found a link that describes similar situation but it doesn't explain much about why this happens or how to solve this issue. It's under the _Why does PyMongo add an id field to all of my documents? in the following link:
https://github.com/mongodb/mongo-python-driver/blob/master/doc/faq.rst#id25