Changed the find-and-insert procedure of mongodb to upsert.