MongoDB Composite Key

后端 未结 3 1294
梦毁少年i
梦毁少年i 2020-12-02 18:52

I\'m just getting started with MongoDb and I\'ve noticed that I get a lot of duplicate records for entries that I meant to be unique. I would like to know how to use a compo

3条回答
  •  我在风中等你
    2020-12-02 19:04

    You can create Unique Indexes on the fields of the document that you'd want to test uniqueness on. They can be composite as well (called compound key indexes in MongoDB land), as you can see from the documentation. Morphia does have a @Indexed annotation to support indexing at the field level. In addition with morphia you can define compound keys at the class level with the @Indexed annotation.

提交回复
热议问题