File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,34 @@ func CreateCollections(config *config.Config) {
8787}
8888```
8989
90+ ### Create Unique Index
91+
92+ ``` go
93+ func CreateIndex () {
94+ mongodb_client.CreateUniqueIndex (" dbName" , " collectionName" , " emailId" )
95+ }
96+ ```
97+
98+ ### Create Index
99+
100+ ``` go
101+ func CreateIndex () {
102+ // For Single Field
103+ indexModel := mongo.IndexModel {
104+ Keys: bson.M {" YOUR_FIELD_NAME" : 1 },
105+ Options: options.Index ().SetUnique (true ),
106+ }
107+
108+ // For Multiple Fields
109+ indexModel := mongo.IndexModel {
110+ Keys: bson.M {" YOUR_FIELD_NAME" : 1 , " ANOTHER_FIELD_NAME" : 1 },
111+ Options: options.Index ().SetUnique (true ),
112+ }
113+
114+ mongodb_client.CreateIndex (" YOUR_DB_NAME" , " YOUR_COLLECTION_NAME" , indexModel)
115+ }
116+ ```
117+
90118## 📦 Usage of Base Model and Repository Functions
91119
92120### 📦 Base DML Model
You can’t perform that action at this time.
0 commit comments