Updated upsert to allow arrays of documents