fix logic in mongo casting to doc