added a second replace document method which works with a metadata aware entity