How to create compund index with mgo

91 views
Skip to first unread message

melvin davis

unread,
Apr 27, 2016, 1:58:18 PM4/27/16
to mgo-users
Hi,

I have something like this :- 

UsersDocument= mgo.Index{
  Key:        []string{"emailid", "purpose"},
  Unique:     true,
  DropDups:   true,
  Background: true,
  Sparse:     true,
}

But I want it to be compund index unique. How can I implement the same?

Thanks in advance...

施舜元

unread,
Apr 29, 2016, 5:03:53 AM4/29/16
to mgo-users
I think this one has already generated a compound unique index.

index = mgo.Index{
Key:    []string{"xxx", "Name"},
Unique: true,
}
err = col.EnsureIndex(index)


Have you checked this on any mongo UI?

melvin davis於 2016年4月28日星期四 UTC+8上午1時58分18秒寫道:
Reply all
Reply to author
Forward
0 new messages