lungo
lungo copied to clipboard
Dump or export
With other projects, you can dump to SQL, or export to CSV:
- https://sqlite.org/cli.html#converting_an_entire_database_to_an_ascii_text_file
- https://sqlite.org/cli.html#export_to_csv
Is something like this possible with Lungo?
The FileStore storage adapter currently stores the full database as one BSON file. If you count BSON as an export format then the storage format would satisfy this already. Otherwise there is no other export or dump function implemented ATM.
In the future, it would be interesting to support the MongoDB dump format either directly with a storage adapter or through methods that dump or restore to/from that format.
Here is a simpler method:
package main
import (
"encoding/json"
"github.com/256dpi/lungo"
"go.mongodb.org/mongo-driver/bson"
"log"
"os"
)
type post struct {
Title string `bson:"title"`
}
func main() {
opts := lungo.Options{
Store: lungo.NewFileStore("lungo.db", os.ModePerm),
}
client, engine, e := lungo.Open(nil, opts)
if e != nil {
log.Fatal(e)
}
defer engine.Close()
csr, e := client.Database("month").Collection("March").Find(nil, bson.M{})
if e != nil {
log.Fatal(e)
}
var posts []post
csr.All(nil, &posts)
create_o, e := os.Create("post.json")
if e != nil {
log.Fatal(e)
}
json_o := json.NewEncoder(create_o)
json_o.SetIndent("", " ")
json_o.Encode(posts)
}