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 { 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.NewErrorIterator(err) } } return model.NewObjectIterator(docs...) }
// Returns an iterator for all refs without error and a slice of the errors func FailsafeDereferenceIterator(refs ...Ref) (i model.Iterator, errors []error) { var docs []interface{} for i := range refs { doc, err := refs[i].Get() if err == nil { docs = append(docs, doc) } else { err = errs.Format("%s: %s", refs[i].ID.Hex(), err.Error()) errors = append(errors, err) } } return model.NewObjectIterator(docs...), errors }
// 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 *DocumentBase) Iterator() model.Iterator { return model.NewObjectIterator(self.embeddingStruct) }