Skip to content

Commit 22caeb5

Browse files
committed
Add "Importing and Exporting Collections" section
1 parent c734318 commit 22caeb5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ docId, _ := db.InsertOne("myCollection", doc)
7979
fmt.Println(docId)
8080
```
8181

82+
### Importing and Exporting Collections
83+
84+
CloverDB is capable of easily importing and exporting collections to JSON format regardless of the storage engine used.
85+
86+
```go
87+
// dump the content of the "todos" collection in a "todos.json" file
88+
db.ExportCollection("todos", "todos.json")
89+
90+
...
91+
92+
// recover the todos collection from the exported json file
93+
db.DropCollection("todos")
94+
db.ImportCollection("todos", "todos.json")
95+
96+
docs, _ := db.Query("todos").FindAll()
97+
for _, doc := range docs {
98+
log.Println(doc)
99+
}
100+
```
101+
82102
## Queries
83103

84104
CloverDB is equipped with a fluent and elegant API to query your data. A query is represented by the **Query** object, which allows to retrieve documents matching a given **criterion**. A query can be created by passing a valid collection name to the `Query()` method.

0 commit comments

Comments
 (0)