complete the write-to-mongodb part