Skip to content
Advertisement

How to make a combined set of fields unique in Mongodb in Python

I want to create a table where two of its fields combine to form an index field. My Python code for creating the table is as follows. What I want to do is make the combined fields course_name and group_name unique so that no two groups with the same course_name and group_name can be created. Can someone please help me with this?

JavaScript

Advertisement

Answer

You can specify indexes in the meta dict of the class:

JavaScript
Advertisement