How do you select all records from a mongodb collection in golang using mgo

后端 未结 2 1457
轻奢々
轻奢々 2021-02-18 19:49

In MongoDB doing something like db.mycollection.find() returns all documents in a collection.

When working in GoLang using the package labix.org/v2/

2条回答
  •  难免孤独
    2021-02-18 20:02

    Found a solution:

        var results []client
    
        err := db.C("client").Find(nil).All(&results)
        if err != nil {
            // TODO: Do something about the error
        } else {
            fmt.Println("Results All: ", results) 
        }
    

提交回复
热议问题