DocumentIterator usage can corrupt data if you forget to zero/nil your buffer
- Vorherrschende Sprache
- Go
- Sterne
- 31
- Forks
- 26
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Since it is a slice reference, any nested structs or arrays in your data will be sparsely overwritten during iteration and can still include old data from past iteration if you follow the docs:
```func main() {
// ...
var docs []Document
iterator := documentdb.NewIterator(
client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
)
for iterator.Next() {
if err := iterator.Error(); err != nil {
log.Fatal(err)
}
fmt.Println(len(docs))
}
// ...
}```
Instead, nil the buffer like this:
```
func main() {
// ...
var docs []Document
iterator := documentdb.NewIterator(
client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
)
for iterator.Next() {
if err := iterator.Error(); err != nil {
log.Fatal(err)
}
fmt.Println(len(docs))
docs = nil // zero your buffer to avoid corrupt data!
}
// ...
}```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.