check if doc._id is undefined before doing an index lookup