Versions in this module Expand all Collapse all v3 v3.0.4 Apr 20, 2023 v3.0.3 Aug 5, 2022 v3.0.2 Jul 18, 2022 v3.0.1 Jul 15, 2022 v3.0.0 Jul 15, 2022 Changes in this version + var ErrCursor = errors.New("invalid cursor") + var ErrNoTransaction = errors.New("no transaction in progress") + var ErrNotFound = errors.New("not found") + func IsDup(err error) bool + func IsNotPrimaryError(err error) bool + func IsRetryable(err error) bool + func IsSnapshotError(err error) bool + func IsTxnAborted(err error) bool + func ResetStats() + func SetDebug(debug bool) + func SetLogger(logger log_Logger) + func SetStats(enabled bool) + type BuildInfo struct + Bits int + Debug bool + GitVersion string + MaxObjectSize int + OpenSSLVersion string + SysInfo string + Version string + VersionArray []int + func (bi *BuildInfo) VersionAtLeast(version ...int) bool + type Bulk struct + func (b *Bulk) Insert(docs ...interface{}) + func (b *Bulk) Remove(selectors ...interface{}) + func (b *Bulk) RemoveAll(selectors ...interface{}) + func (b *Bulk) Run() (*BulkResult, error) + func (b *Bulk) Unordered() + func (b *Bulk) Update(pairs ...interface{}) + func (b *Bulk) UpdateAll(pairs ...interface{}) + func (b *Bulk) Upsert(pairs ...interface{}) + type BulkError struct + func (e *BulkError) Cases() []BulkErrorCase + func (e *BulkError) Error() string + type BulkErrorCase struct + Err error + Index int + type BulkResult struct + Matched int + Modified int + type Change struct + Remove bool + ReturnNew bool + Update interface{} + Upsert bool + type ChangeInfo struct + Matched int + Removed int + Updated int + UpsertedId interface{} + type Collation struct + Alternate string + Backwards bool + CaseFirst string + CaseLevel bool + Locale string + NumericOrdering bool + Strength int + type Collection struct + Database *Database + FullName string + Name string + func (c *Collection) Bulk() *Bulk + func (c *Collection) Count() (n int, err error) + func (c *Collection) Create(info *CollectionInfo) error + func (c *Collection) DropCollection() error + func (c *Collection) DropIndex(key ...string) error + func (c *Collection) DropIndexName(name string) error + func (c *Collection) EnsureIndex(index Index) error + func (c *Collection) EnsureIndexKey(key ...string) error + func (c *Collection) Find(query interface{}) *Query + func (c *Collection) FindId(id interface{}) *Query + func (c *Collection) Indexes() (indexes []Index, err error) + func (c *Collection) Insert(docs ...interface{}) error + func (c *Collection) NewIter(session *Session, firstBatch []bson.Raw, cursorId int64, err error) *Iter + func (c *Collection) Pipe(pipeline interface{}) *Pipe + func (c *Collection) Remove(selector interface{}) error + func (c *Collection) RemoveAll(selector interface{}) (info *ChangeInfo, err error) + func (c *Collection) RemoveId(id interface{}) error + func (c *Collection) Repair() *Iter + func (c *Collection) Update(selector interface{}, update interface{}) error + func (c *Collection) UpdateAll(selector interface{}, update interface{}) (info *ChangeInfo, err error) + func (c *Collection) UpdateId(id interface{}, update interface{}) error + func (c *Collection) Upsert(selector interface{}, update interface{}) (info *ChangeInfo, err error) + func (c *Collection) UpsertId(id interface{}, update interface{}) (info *ChangeInfo, err error) + func (c *Collection) With(s *Session) *Collection + type CollectionInfo struct + Capped bool + DisableIdIndex bool + ForceIdIndex bool + MaxBytes int + MaxDocs int + StorageEngine interface{} + ValidationAction string + ValidationLevel string + Validator interface{} + type Credential struct + Mechanism string + Password string + Service string + ServiceHost string + Source string + Username string + type DBRef struct + Collection string + Database string + Id interface{} + type Database struct + Name string + Session *Session + func (db *Database) AddUser(username, password string, readOnly bool) error + func (db *Database) C(name string) *Collection + func (db *Database) CollectionNames() (names []string, err error) + func (db *Database) DropDatabase() error + func (db *Database) FindRef(ref *DBRef) *Query + func (db *Database) GridFS(prefix string) *GridFS + func (db *Database) Login(user, pass string) error + func (db *Database) Logout() + func (db *Database) RemoveUser(user string) error + func (db *Database) Run(cmd interface{}, result interface{}) error + func (db *Database) UpsertUser(user *User) error + func (db *Database) With(s *Session) *Database + type DialInfo struct + Addrs []string + Database string + Dial func(addr net.Addr) (net.Conn, error) + DialServer func(addr *ServerAddr) (net.Conn, error) + Direct bool + FailFast bool + Mechanism string + Password string + PoolLimit int + ReplicaSetName string + Service string + ServiceHost string + SocketTimeout time.Duration + Source string + SyncTimeout time.Duration + Timeout time.Duration + Username string + func ParseURL(url string) (*DialInfo, error) + type GridFS struct + Chunks *Collection + Files *Collection + func (gfs *GridFS) Create(name string) (file *GridFile, err error) + func (gfs *GridFS) Find(query interface{}) *Query + func (gfs *GridFS) Open(name string) (file *GridFile, err error) + func (gfs *GridFS) OpenId(id interface{}) (file *GridFile, err error) + func (gfs *GridFS) OpenNext(iter *Iter, file **GridFile) bool + func (gfs *GridFS) Remove(name string) (err error) + func (gfs *GridFS) RemoveId(id interface{}) error + type GridFile struct + func (file *GridFile) Abort() + func (file *GridFile) Close() (err error) + func (file *GridFile) ContentType() string + func (file *GridFile) GetMeta(result interface{}) (err error) + func (file *GridFile) Id() interface{} + func (file *GridFile) MD5() (md5 string) + func (file *GridFile) Name() string + func (file *GridFile) Read(b []byte) (n int, err error) + func (file *GridFile) Seek(offset int64, whence int) (pos int64, err error) + func (file *GridFile) SetChunkSize(bytes int) + func (file *GridFile) SetContentType(ctype string) + func (file *GridFile) SetId(id interface{}) + func (file *GridFile) SetMeta(metadata interface{}) + func (file *GridFile) SetName(name string) + func (file *GridFile) SetUploadDate(t time.Time) + func (file *GridFile) Size() (bytes int64) + func (file *GridFile) UploadDate() time.Time + func (file *GridFile) Write(data []byte) (n int, err error) + type Index struct + Background bool + Bits int + BucketSize float64 + Collation *Collation + DefaultLanguage string + DropDups bool + ExpireAfter time.Duration + Key []string + LanguageOverride string + Max int + Maxf float64 + Min int + Minf float64 + Name string + Sparse bool + Unique bool + Weights map[string]int + type Iter struct + func (iter *Iter) All(result interface{}) error + func (iter *Iter) Close() error + func (iter *Iter) Done() bool + func (iter *Iter) Err() error + func (iter *Iter) For(result interface{}, f func() error) (err error) + func (iter *Iter) Next(result interface{}) bool + func (iter *Iter) Timeout() bool + type LastError struct + Code int + Err string + FSyncFiles int + N int + UpdatedExisting bool + UpsertedId interface{} + WTimeout bool + Waited int + func (err *LastError) Error() string + type MapReduce struct + Finalize string + Map string + Out interface{} + Reduce string + Scope interface{} + Verbose bool + type MapReduceInfo struct + Collection string + Database string + EmitCount int + InputCount int + OutputCount int + Time int64 + VerboseTime *MapReduceTime + type MapReduceTime struct + EmitLoop int64 + Map int64 + Total int64 + type Mode int + const Eventual + const Monotonic + const Nearest + const Primary + const PrimaryPreferred + const Secondary + const SecondaryPreferred + const Strong + type Pipe struct + func (p *Pipe) All(result interface{}) error + func (p *Pipe) AllowDiskUse() *Pipe + func (p *Pipe) Batch(n int) *Pipe + func (p *Pipe) Explain(result interface{}) error + func (p *Pipe) Iter() *Iter + func (p *Pipe) One(result interface{}) error + type Query struct + func (q *Query) All(result interface{}) error + func (q *Query) Apply(change Change, result interface{}) (info *ChangeInfo, err error) + func (q *Query) Batch(n int) *Query + func (q *Query) Comment(comment string) *Query + func (q *Query) Count() (n int, err error) + func (q *Query) Distinct(key string, result interface{}) error + func (q *Query) Explain(result interface{}) error + func (q *Query) For(result interface{}, f func() error) error + func (q *Query) Hint(indexKey ...string) *Query + func (q *Query) Iter() *Iter + func (q *Query) Limit(n int) *Query + func (q *Query) LogReplay() *Query + func (q *Query) MapReduce(job *MapReduce, result interface{}) (info *MapReduceInfo, err error) + func (q *Query) One(result interface{}) (err error) + func (q *Query) Prefetch(p float64) *Query + func (q *Query) Select(selector interface{}) *Query + func (q *Query) SetMaxScan(n int) *Query + func (q *Query) SetMaxTime(d time.Duration) *Query + func (q *Query) Skip(n int) *Query + func (q *Query) Snapshot() *Query + func (q *Query) Sort(fields ...string) *Query + func (q *Query) Tail(timeout time.Duration) *Iter + type QueryError struct + Assertion bool + Code int + Message string + func (err *QueryError) Error() string + type Role string + const RoleClusterAdmin + const RoleDBAdmin + const RoleDBAdminAny + const RoleRead + const RoleReadAny + const RoleReadWrite + const RoleReadWriteAny + const RoleRoot + const RoleUserAdmin + const RoleUserAdminAny + type Safe struct + FSync bool + J bool + W int + WMode string + WTimeout int + type ServerAddr struct + func (addr *ServerAddr) String() string + func (addr *ServerAddr) TCPAddr() *net.TCPAddr + type Session struct + func Dial(url string) (*Session, error) + func DialWithInfo(info *DialInfo) (*Session, error) + func DialWithTimeout(url string, timeout time.Duration) (*Session, error) + func (s *Session) AbortTransaction() error + func (s *Session) BuildInfo() (info BuildInfo, err error) + func (s *Session) Clone() *Session + func (s *Session) Close() + func (s *Session) CommitTransaction() error + func (s *Session) Copy() *Session + func (s *Session) DB(name string) *Database + func (s *Session) DatabaseNames() (names []string, err error) + func (s *Session) EnsureSafe(safe *Safe) + func (s *Session) FindRef(ref *DBRef) *Query + func (s *Session) Fsync(async bool) error + func (s *Session) FsyncLock() error + func (s *Session) FsyncUnlock() error + func (s *Session) LiveServers() (addrs []string) + func (s *Session) Login(cred *Credential) error + func (s *Session) LogoutAll() + func (s *Session) Mode() Mode + func (s *Session) New() *Session + func (s *Session) Ping() error + func (s *Session) Refresh() + func (s *Session) ResetIndexCache() + func (s *Session) Run(cmd interface{}, result interface{}) error + func (s *Session) Safe() (safe *Safe) + func (s *Session) SelectServers(tags ...bson.D) + func (s *Session) SetBatch(n int) + func (s *Session) SetBypassValidation(bypass bool) + func (s *Session) SetCursorTimeout(d time.Duration) + func (s *Session) SetMode(consistency Mode, refresh bool) + func (s *Session) SetPoolLimit(limit int) + func (s *Session) SetPrefetch(p float64) + func (s *Session) SetSafe(safe *Safe) + func (s *Session) SetSocketTimeout(d time.Duration) + func (s *Session) SetSyncTimeout(d time.Duration) + func (s *Session) StartTransaction() error + type Stats struct + Clusters int + MasterConns int + ReceivedDocs int + ReceivedOps int + SentOps int + SlaveConns int + SocketRefs int + SocketsAlive int + SocketsInUse int + func GetStats() Stats + type User struct + CustomData interface{} + OtherDBRoles map[string][]Role + Password string + PasswordHash string + Roles []Role + UserSource string + Username string Other modules containing this package github.com/juju/mgo/v2