Documentation
¶
Index ¶
- Variables
- func ToAnySlice(docs any) []any
- type ChangeInfo
- type Collection
- func (c *Collection) Count() (int, error)
- func (c *Collection) Database() *Database
- func (c *Collection) DropCollection() error
- func (c *Collection) EnsureIndex(index Index) error
- func (c *Collection) Find(query interface{}) *Query
- func (c *Collection) Insert(docs ...any) error
- func (c *Collection) Remove(selector interface{}) error
- func (c *Collection) RemoveAll(selector interface{}) (*mongo.DeleteResult, error)
- func (c *Collection) RemoveId(id interface{}) error
- func (c *Collection) ReplaceOne(selector, updatedDoc interface{}) error
- func (c *Collection) Update(selector, update interface{}) error
- func (c *Collection) UpdateAll(selector interface{}, update interface{}) (*ChangeInfo, error)
- func (c *Collection) UpdateId(id, update interface{}) error
- func (c *Collection) Upsert(selector, update interface{}) (*mongo.UpdateResult, error)
- func (c *Collection) UpsertId(id, update interface{}) (*mongo.UpdateResult, error)
- type Database
- func (d *Database) AddUser(username, password string, readOnly bool) error
- func (d *Database) C(name string) *Collection
- func (db *Database) CollectionNames() (names []string, err error)
- func (d *Database) DropDatabase() error
- func (d *Database) RemoveUser(username string) error
- func (d *Database) Run(cmd interface{}, result interface{}) error
- func (d *Database) Session() *Session
- type Index
- type Iter
- type Mode
- type Query
- func (q *Query) All(result interface{}) error
- func (q *Query) Collection() *Collection
- func (q *Query) Count() (int, error)
- func (q *Query) CountAll() (int, error)
- func (q *Query) Iter() *Iter
- func (q *Query) Limit(n int) *Query
- func (q *Query) One(result interface{}) error
- func (q *Query) Select(selector interface{}) *Query
- func (q *Query) Skip(n int) *Query
- func (q *Query) Sort(fields ...string) *Query
- type Safe
- type Session
- func (s *Session) Clone() *Session
- func (s *Session) Close()
- func (s *Session) Copy() *Session
- func (s *Session) DB(name string) *Database
- func (s *Session) DatabaseNames() (names []string, err error)
- func (s *Session) Ping() error
- func (s *Session) SetSafe(safe *Safe)
- func (s *Session) SetSocketTimeout(d time.Duration)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound 模拟mgo.v2的ErrNotFound
Functions ¶
Types ¶
type ChangeInfo ¶
type ChangeInfo struct {
// Updated reports the number of existing documents modified.
// Due to server limitations, this reports the same value as the Matched field when
// talking to MongoDB <= 2.4 and on Upsert and Apply (findAndModify) operations.
Updated int
Removed int // Number of documents removed
Matched int // Number of documents matched but not necessarily changed
UpsertedId interface{} // Upserted _id field, when not explicitly provided
}
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection 模拟mgo.v2的Collection
func (*Collection) Database ¶ added in v1.0.3
func (c *Collection) Database() *Database
Database 获取Collection所属的Database
func (*Collection) DropCollection ¶
func (c *Collection) DropCollection() error
DropCollection 模拟mgo.v2的DropCollection方法
func (*Collection) EnsureIndex ¶
func (c *Collection) EnsureIndex(index Index) error
EnsureIndex 模拟mgo.v2的EnsureIndex方法
func (*Collection) Remove ¶
func (c *Collection) Remove(selector interface{}) error
Remove 模拟mgo.v2的Remove方法
func (*Collection) RemoveAll ¶
func (c *Collection) RemoveAll(selector interface{}) (*mongo.DeleteResult, error)
RemoveAll 模拟mgo.v2的RemoveAll方法
func (*Collection) RemoveId ¶
func (c *Collection) RemoveId(id interface{}) error
RemoveId 模拟mgo.v2的RemoveId方法
func (*Collection) ReplaceOne ¶ added in v1.0.4
func (c *Collection) ReplaceOne(selector, updatedDoc interface{}) error
func (*Collection) Update ¶
func (c *Collection) Update(selector, update interface{}) error
Update 模拟mgo.v2的Update方法
func (*Collection) UpdateAll ¶
func (c *Collection) UpdateAll(selector interface{}, update interface{}) (*ChangeInfo, error)
UpdateAll 模拟mgo.v2的UpdateAll方法
func (*Collection) UpdateId ¶
func (c *Collection) UpdateId(id, update interface{}) error
UpdateId 模拟mgo.v2的UpdateId方法
func (*Collection) Upsert ¶
func (c *Collection) Upsert(selector, update interface{}) (*mongo.UpdateResult, error)
Upsert 模拟mgo.v2的Upsert方法
func (*Collection) UpsertId ¶
func (c *Collection) UpsertId(id, update interface{}) (*mongo.UpdateResult, error)
UpsertId 模拟mgo.v2的UpsertId方法
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database 模拟mgo.v2的Database
func (*Database) CollectionNames ¶
CollectionNames 模拟mgo.v2的CollectionNames方法
func (*Database) DropDatabase ¶
DropDatabase 模拟mgo.v2的DropDatabase方法
func (*Database) RemoveUser ¶
RemoveUser 模拟mgo.v2的RemoveUser方法
type Index ¶
type Index struct {
Keys []string
Unique bool
Background bool
Sparse bool
ExpireAfterSeconds int
Name string
}
Index 模拟mgo.v2的Index
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query 模拟mgo.v2的Query
func (*Query) Collection ¶ added in v1.0.3
func (q *Query) Collection() *Collection
Collection 获取Query所属的Collection
type Session ¶
Session 模拟mgo.v2的Session
func DialWithTimeout ¶
DialWithTimeout 模拟mgo.v2的DialWithTimeout函数
func (*Session) DatabaseNames ¶
DatabaseNames 模拟mgo.v2的DatabaseNames
func (*Session) SetSocketTimeout ¶
SetSocketTimeout 模拟mgo.v2的SetSocketTimeout方法