-
Notifications
You must be signed in to change notification settings - Fork 2
/
t.go
40 lines (36 loc) · 851 Bytes
/
t.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
package main
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"time"
)
func main() {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
collection := client.Database("QAREALTIME").Collection("account")
ctx, _ = context.WithTimeout(context.Background(), 30*time.Second)
cur, err := collection.Find(
ctx,
bson.D{
{"broker_name", "QUANTAXIS"},
})
if err != nil {
log.Fatal(err)
}
defer cur.Close(ctx)
for cur.Next(ctx) {
var result bson.M
err := cur.Decode(&result)
if err != nil {
log.Fatal(err)
}
// do something with result....
log.Println(result)
}
if err := cur.Err(); err != nil {
log.Fatal(err)
}
}