func ensureIndexes() { ses := mongo.GetSession() defer ses.Close() index := mgo.Index{ Key: []string{"public_id"}, Unique: false, } mongo.GetCollection(ses, session.Collection).EnsureIndex(index) }
// runCreate is the code that implements the create command. func runCreate(cmd *cobra.Command, args []string) { db, err := retrieveDatabaseMetadata(create.file) if err != nil { dbCmd.Printf("Error reading collections : %s : ERROR : %v\n", create.file, err) return } ses := mongo.GetSession() defer ses.Close() cmd.Println("Configuring database", mongo.GetDatabaseName()) for _, col := range db.Cols { cmd.Println("Creating collection", col.Name) if err := createCollection(ses, db, &col, true); err != nil && err != ErrCollectionExists { cmd.Println("ERROR:", err) return } } }
// NewMGO return a new DB value for use with MongoDB. func NewMGO() *DB { return &DB{ MGOConn: mongo.GetSession(), } }