This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func PopulateIndex(database, collection string, client *mongo.Client) { | |
c := client.Database(database).Collection(collection) | |
opts := options.CreateIndexes().SetMaxTime(10 * time.Second) | |
index := yieldIndexModel() | |
c.Indexes().CreateOne(context.Background(), index, opts) | |
log.Println("Successfully create the index") | |
} | |
func yieldIndexModel() mongo.IndexModel { | |
keys := bsonx.Doc{{Key: *key, Value: bsonx.Int32(int32(*value))}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"flag" | |
"log" | |
"github.com/mongodb/mongo-go-driver/mongo" | |
) | |
var ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "flag" | |
var ( | |
cmd = flag.String("cmd", "", "list or add?") | |
address = flag.String("address", "", "mongodb address to connect to") | |
database = flag.String("db", "", "The name of the database to connect to") | |
collection = flag.String("collection", "", "The collection (in the db) to connect to") | |
key = flag.String("field", "", "The field you'd like to place an index on") |
NewerOlder