patched to convert ObjectIds in query to strings since ObjectIds cause exceptions