Update and insert all in one go! (I’m sure this worked with ruby mongo driver version 1. I just didn’t realize it until I read this stackoverflow question on upsert). Here’s the relevant code snippet (“id” is the instagram string unique id not to be confused with mongo’s unique id which is “_id”):

photosColl.find({ 'id' => id }).update_one(photo,:upsert => true )