| 1234567891011121314151617181920212223 | 
							- package mo
 
- import (
 
- 	"go.mongodb.org/mongo-driver/mongo/options"
 
- )
 
- // NewJsonSchema
 
- // reference https://docs.mongodb.com/manual/reference/command/collMod/#mongodb-collflag-validator
 
- func NewJsonSchema(collName string, jsonSchema M) D {
 
- 	return D{{Key: "collMod", Value: collName}, {"validator", E{Key: "$jsonSchema", Value: jsonSchema}}}
 
- }
 
- // NewIndex create index list from field
 
- func NewIndex(field []string) []IndexModel {
 
- 	index := make([]IndexModel, len(field))
 
- 	for i := 0; i < len(field); i++ {
 
- 		index[i] = IndexModel{
 
- 			Keys:    M{field[i]: 1},
 
- 			Options: options.Index().SetUnique(true),
 
- 		}
 
- 	}
 
- 	return index
 
- }
 
 
  |