time.go 819 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "time"
  6. "github.com/globalsign/mgo"
  7. "github.com/globalsign/mgo/bson"
  8. "github.com/tal-tech/go-zero/core/stores/mongo"
  9. )
  10. type Roster struct {
  11. Id bson.ObjectId `bson:"_id"`
  12. CreateTime time.Time `bson:"createTime"`
  13. Classroom mgo.DBRef `bson:"classroom"`
  14. Member mgo.DBRef `bson:"member"`
  15. DisplayName string `bson:"displayName"`
  16. }
  17. func main() {
  18. model := mongo.MustNewModel("localhost:27017/blackboard", "roster")
  19. for i := 0; i < 1000; i++ {
  20. session, err := model.TakeSession()
  21. if err != nil {
  22. log.Fatal(err)
  23. }
  24. var roster Roster
  25. filter := bson.M{"_id": bson.ObjectIdHex("587353380cf2d7273d183f9e")}
  26. fmt.Println(model.GetCollection(session).Find(filter).One(&roster))
  27. model.PutSession(session)
  28. }
  29. time.Sleep(time.Hour)
  30. }