-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
48 lines (38 loc) · 1014 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
42
43
44
45
46
47
48
// CLI only. Exports results from MongoDB to CLI. That's all
package main
import (
"dblogin"
"fmt"
"time"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
// main is the entry point for the program
type personaFields struct {
ID bson.ObjectId `bson:"_id,omitempty"`
Name string
Phone string
Timestamp time.Time
}
func main() {
p := fmt.Println
session, err := mgo.Dial(dblogin.Userpass) // mongodb://username:yourpasscode@serverip:27017/database?authSource=admin
if err != nil {
panic(err)
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
// Collection People
c := session.DB("test").C("people")
var results []personaFields
// Query All
err = c.Find(bson.M{}).Sort("-timestamp").All(&results)
if err != nil {
panic(err)
}
for _, v := range results {
//t1, e := time.Parse(time.RFC3339, "2012-08-11T22:08:41+00:00")
p(v.Phone, "\t", v.Timestamp.Format("2006-01-02 3:04PM"), "\t", v.Name, "\t")
}
fmt.Printf("Total results: %d\n", len(results))
}