bolt
bolt copied to clipboard
Only the first level of ForEach()
...
return db.View(func(tx *bolt.Tx) error {
return tx.ForEach(func(name []byte, bkt *bolt.Bucket) error {
// "some data" here...
return bkt.Tx().ForEach(func(n []byte, b *bolt.Bucket) {
// "other data" here...
// but logs and get actions return "some data"
})
})
})
ForEach()
does not work beyond the first level of buckets and shows the same data that is stored above the specified ForEach()
.
ForEach executes a function for each bucket in the root. If the provided function returns an error then the iteration is stopped and the error is returned to the caller.
Instead you probably want to use Bucket.Cursor() or Bucket.ForEach().
When using Bucket.Cursor: if the value is nil, the key is a bucket name. Otherwise it's just a key/value pair.
Here's an example for recursively dumping every bucket and key/value pair: https://gist.github.com/chilts/6bd440c056f85e9c2c6114c017ecab1e