Morphia: Saving document in a specific collection

158 Views Asked by At

I am using Morphia 2.x, and I have a usecase where i want to save 1 Entity class into 2 different Collections. However Morphia 2.x save method doesn't have any option to pass a Collection Name, Where as Morphia 1.x had this option. I am not sure why they have removed this option.

@Entity
public class Unit {
    @Id
    private String id;
    protected Unit() {
    }

    public String getId() {
        return this.id;
    }

    public void setId(final String id) {
        this.id = id;
    }
}
1

There are 1 best solutions below

0
evanchooly On

Morphia 2.3 will reintroduce this functionality as an option passed via the alternateCollection option on InsertOneOptions (among other options classes). I'm working to get this out soon.