Composite Primary Key

155 views
Skip to first unread message

Raichu

unread,
Nov 1, 2014, 1:51:24 PM11/1/14
to mongo-jack...@googlegroups.com
Hi,
  I need to use a composite primary key in one my collection. We are not getting how to place @Id annotation to make it composite.

 If already asked & answered; please provide link for the same.
  

Stanislav Vasilev

unread,
Nov 2, 2014, 3:22:08 AM11/2/14
to mongo-jack...@googlegroups.com
Hi Raichu,

There is no such concept like composite primary key in MongoDb. You only have one document id. You can use a combination of unique keys to achieve part of your requirements and handle the rest of the logic in your application.

Raichu

unread,
Nov 2, 2014, 3:37:37 AM11/2/14
to mongo-jack...@googlegroups.com
Thanks for reply. Actually we were trying to keep number of indexes low. But we need to create composite indexes and handle them. 

Raichu

unread,
Nov 2, 2014, 11:20:05 AM11/2/14
to mongo-jack...@googlegroups.com
Hi,
  I may have put the question wrongly. Actually we are trying to this
{
    "_id" : {
            "user" : "123",
            "address" : "1"
        },
"address" : "abc"
}

we want to combine two fields to get single _id 
Is this possible in mongojack?

James Roper

unread,
Nov 2, 2014, 5:03:02 PM11/2/14
to mongo-jack...@googlegroups.com
Have you tried it?  Why wouldn't it be possible?

--
You received this message because you are subscribed to the Google Groups "mongo-jackson-mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongo-jackson-ma...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashwani kr Kushwaha

unread,
Nov 2, 2014, 11:31:21 PM11/2/14
to mongo-jack...@googlegroups.com
Yes we were able to make it work like this 
private static JacksonDBCollection<Test, TestKey> coll = MongoDB.getCollection("test", Test.class, TestKey.class);
we were missing to pass testkey as argument

--
You received this message because you are subscribed to a topic in the Google Groups "mongo-jackson-mapper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongo-jackson-mapper/S3g7H0bPk2g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongo-jackson-ma...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages