fix bug when empty docs or collections