func newIterator(query Query) model.Iterator { mgoQuery, err := query.mongoQuery() if err != nil { return model.NewErrorOnlyIterator(err) } mgoIter := mgoQuery.Iter() collection, selectors := collectionAndSubDocumentSelectors(query) return &MongoIterator{collection: collection, selectors: selectors, iter: mgoIter} }
func NewMongoIterator(query Query) model.Iterator { mgoQuery, err := query.mongoQuery() if err != nil { return model.NewErrorOnlyIterator(err) } return &MongoIterator{collection: query.Collection(), iter: mgoQuery.Iter()} // mgoIter := mgoQuery.Iter() // collection, selectors := collectionAndSubDocumentSelectors(query) // return &MongoIterator{collection: collection, selectors: selectors, iter: mgoIter} }
// Returns an iterator of dereferenced refs, or an error iterator if there was an error func DereferenceIterator(refs ...Ref) model.Iterator { docs := make([]interface{}, len(refs)) for i := range refs { var err error docs[i], err = refs[i].Get() if err != nil { err = errs.Format("%s: %s", refs[i].ID.Hex(), err.Error()) return model.NewErrorOnlyIterator(err) } } return model.NewObjectIterator(docs...) }
func (self *Collection) TryDocumentWithIDIterator(id bson.ObjectId, subDocSelectors ...string) model.Iterator { if len(subDocSelectors) > 0 { panic("Sub document selectors are not implemented") } document, ok, err := self.TryDocumentWithID(id, subDocSelectors...) if err != nil { return model.NewErrorOnlyIterator(err) } if !ok { return model.NewObjectIterator() } return model.NewObjectIterator(document) }
// Returns an iterator of dereferenced refs, or an error iterator if there was an error func DereferenceIterator(refs ...Ref) model.Iterator { var docs []interface{} for i := range refs { doc, err := refs[i].Get() if err != nil { err = errs.Format("%s: %s", refs[i].ID.Hex(), err.Error()) return model.NewErrorOnlyIterator(err) } else if doc != nil { docs = append(docs, doc) } } return model.NewObjectIterator(docs...) }
func (self *QueryError) Iterator() model.Iterator { return model.NewErrorOnlyIterator(self.Err) }