Reputation: 189
I was hoping that I could just $set using "row" as it contains all the data I would want to update but get the following. My code is below:
c:\mongo scripts>csvimporter.py Traceback (most recent call last): .... pymongo.errors.WriteError: An empty update path is not valid.
def import_fame_dump(input_file='AB.csv'):
fame_export = csv.DictReader(open(input_file), dialect='excel')
leads = []
fame_export.fieldnames + ['ImportDate']
for row in fame_export:
row['ImportDate'] = datetime.datetime.utcnow()
#leads.append(row)
result = db.leads.update_one({
'match1': row['match1'],
'match2': row['match2'],
'match3': row['match3'],
'match4': row['match4']
}, {"$set": row },
upsert=True)
Many thanks for any assistance.
Upvotes: 3
Views: 3160
Reputation: 24007
Print out the value of "row", or set a breakpoint in your debugger, so you know what you're sending to MongoDB.
At some point you have an empty string as a key, doing the equivalent of this:
> db.collection.update({match1: '1'}, {$set: {'': 2}})
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 56,
"errmsg" : "An empty update path is not valid."
}
})
Upvotes: 1