/
main.go
41 lines (36 loc) · 906 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"flag"
"gopkg.in/mgo.v2"
)
func main() {
mongodAddr := flag.String("addr", "127.0.0.1:27017", "-addr=127.0.0.1:27017")
switchFind := flag.Bool("find", false, "-find")
switchMapReduce := flag.Bool("mapreduce", false, "-mapreduce")
switchInsert := flag.Bool("insert", false, "-insert")
switchInit := flag.Bool("init", false, "-init")
switchTree := flag.Bool("tree", false, "-tree")
flag.Parse()
session, err := mgo.Dial(*mongodAddr)
if err != nil {
panic(err)
}
defer session.Close()
dbName := "study"
collectionName := "test1"
db := session.DB(dbName)
collection := db.C(collectionName)
if *switchFind {
find(collection)
} else if *switchMapReduce {
mapreduce(collection)
} else if *switchInsert {
insert(collection)
} else if *switchInit {
initCollection(collection, 10000)
} else if *switchTree {
tree(db)
} else {
flag.PrintDefaults()
}
}