Eliminate test db lookups which depend on ordering

Change all DB lookups which use ".at(0)" or similar, which expect
collection ordering, to calls that are ordering-independent, to ensure
that tests function on different OSes/installs.