Exemplo n.º 1
0
func ensureIndexes() {
	ses := mongo.GetSession()
	defer ses.Close()

	index := mgo.Index{
		Key:    []string{"public_id"},
		Unique: false,
	}

	mongo.GetCollection(ses, session.Collection).EnsureIndex(index)
}
Exemplo n.º 2
0
// 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
		}
	}
}
Exemplo n.º 3
0
// NewMGO return a new DB value for use with MongoDB.
func NewMGO() *DB {
	return &DB{
		MGOConn: mongo.GetSession(),
	}
}