mongodbmongo-javamongo-jackson-mappermongojack

Mongojack- how to create composite Primary key


We are using mongodb & MongoJack for mapping our collections. There is a need where we need to create composite primary key. We are not getting correct configuration how to use @Id annotation.

Can anyone help in this or should we avoid using mapper for the same?

MongoDB Composite Key link tells what we want to do . But we want this through mongojack..


Solution

  • Below syntax should work. Note replacing String class with your Key class

    private static JacksonDBCollection<Test, TestKey> coll = MongoDB.getCollection("test", Test.class, TestKey.class);