Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 14d1c0afcc
Fetching contributors…

Cannot retrieve contributors at this time

file 74 lines (59 sloc) 1.301 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
// Copyright 2009,2010 The 'gomongo' Authors. All rights reserved.
// Use of this source code is governed by the New BSD License
// that can be found in the LICENSE file.

package mongo

import (
"container/vector"
"os"
)


type Cursor struct {
collection *Collection
id int64
pos int
docs *vector.Vector
}

func (self *Cursor) HasMore() bool {
if self.pos < self.docs.Len() {
return true
}

err := self.GetMore()
if err != nil {
return false
}

return self.pos < self.docs.Len()
}

func (self *Cursor) GetNext() (BSON, os.Error) {
if self.HasMore() {
doc := self.docs.At(self.pos).(BSON)
self.pos = self.pos + 1
return doc, nil
}
return nil, os.NewError("cursor failure")
}

func (self *Cursor) GetMore() os.Error {
if self.id == 0 {
return os.NewError("no cursorID")
}

gm := &opGetMore{self.collection.fullName(), 0, self.id}
conn := self.collection.db.Conn
err := conn.writeOp(gm)
if err != nil {
return err
}

reply, err := conn.readReply()
if err != nil {
return err
}

self.pos = 0
self.docs = reply.documents

return nil
}

func (self *Cursor) Close() os.Error {
if self.id == 0 {
// not open on server
return nil
}

km := &opKillCursors{1, []int64{self.id}}
conn := self.collection.db.Conn
return conn.writeOp(km)
}
Something went wrong with that request. Please try again.