The solution with @Document(collection = "impressions") works, if you store the object only in one collection and the name of the collection is different than the default name. If you store an object in multiple collections you have to create the indexes manually. Maybe in such a scenario the annotation approach does not provide any benefit.
Code:
public class UserString {
private String id;
private String userName;
}
mongoTemplate.ensureIndex(new Index("userName", Order.ASCENDING), "customer1.users");
mongoTemplate.ensureIndex(new Index("userName", Order.ASCENDING), "customer2.users");
mongoTemplate.save(new User("ralph"), "customer1.users");
mongoTemplate.save(new User("stefan"), "customer1.users");
mongoTemplate.save(new User("john"), "customer2.users");
mongoTemplate.save(new User("adam"), "customer2.users");