Skip to content

Instantly share code, notes, and snippets.

@Hasstrup
Hasstrup / main.go
Last active December 29, 2018 19:35
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))}}
@Hasstrup
Hasstrup / main.go
Last active December 29, 2018 21:32
package main
import (
"context"
"flag"
"log"
"github.com/mongodb/mongo-go-driver/mongo"
)
var (
@Hasstrup
Hasstrup / main.go
Last active December 29, 2018 21:31
Index
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")