Beispiel #1
0
func (c *Cursor) FetchN(qty int, ds *base.DataSet, closeCursor bool) error {
	var e error
	e = c.validate()
	if e != nil {
		return e
	}
	if c.mgoIter == nil {
		e = c.ResetFetch()
		if e != nil {
			return e
		}
	}
	if closeCursor {
		defer c.Close()
	}

	scan := true
	i := 0
	for scan {
		dataHolder := ds.Model()
		if boolIter := c.mgoIter.Next(dataHolder); boolIter {
			ds.Data = append(ds.Data, dataHolder)
			i = i + 1
			if i == qty {
				scan = false
			}
		} else {
			scan = false
		}
	}

	return nil
}
Beispiel #2
0
func (c *Cursor) FetchN(nCount int, resultDataSet *base.DataSet, closeCursor bool) error {
	resultInside := []toolkit.M{}

	_, e := c.doFetch(nCount, &resultInside, func(each toolkit.M) {
		resultDataSet.Data = append(resultDataSet.Data, each)
	}, closeCursor)

	if e != nil {
		return e
	}

	return nil
}