Question: I'm trying to read a collection dump generated by mongodump. The file is a few gigabytes so I want to read it incrementally.

I can read the first object with something like this:

```
buf := make([]byte, 100000)
f, _ := os.Open(path)
f.Read(buf)

var m bson.M
bson.Unmarshal(buf, &m)

```

However I don't know how much of the buf was consumed, so I don't know how to read the next one.

Is this possible with mgo?

Answer: 
I managed to solve it with the following code:

```
for len(buf) > 0 {
    var r bson.Raw
    var m userObject

    bson.Unmarshal(buf, &r)
    r.Unmarshal(&m)

    fmt.Println(m)

    buf = buf[len(r.Data):]
}

```
The method `File.Read` returns the number of bytes read.

[File.Read](http://golang.org/pkg/os/#File.Read)

> 
> Read reads up to len(b) bytes from the File. It returns the number of bytes read and an error, if any. EOF is signaled by a zero count with err set to io.EOF. 
> 
> 
> 

So you can get the number of bytes read by simply storing the return parameters of you read:

```
n, err := f.Read(buf)

```