# README
仿造GORM接口的MongoDB数据库操作,使用方法参考GORM文档
https://gorm.io/zh_CN/docs/create.html
查找
db.Find(&struct{},where)
db.Model(&struct{}).Find(&map{},where)
使用Omit排除部分columns db.Omit(columns ...string).Find(&struct{},where)
使用Select选定部分columns,只返回选定字段值 db.Select(columns ...string).Find(&struct{},where)
更新
更新所有非空字段: db.Update(&struct{},where)
更新MAP中所有值: db.Model(&struct{}).Update(&map{},where)
排除Omit中的字段: db.Omit(columns ...string).Update(&struct{},where)
只更新Select的字段: db.Select(columns ...string).Update(&struct{},where)
更新并同步内存数据
更新,并将修改后的结果同步更新到Model(&struct{})中,可以配合Omit,Select 排除/选定字段
db.Model(&struct{},true).Update(&map{}|&struct{},where)
# Functions
New address uri || *mongo.Client.
NewClient
uri实例 mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[dbname][?options]]
mongodb:// 前缀,代表这是一个Connection String
username:password@ 如果启用了鉴权,需要指定用户密码
hostX:portX 多个 mongos 的地址列表
/dbname 鉴权时,用户帐号所属的数据库
?options 指定额外的连接选项
read preference
1)primary : 主节点,默认模式,读操作只在主节点,如果主节点不可用,报错或者抛出异常。
2)primaryPreferred:首选主节点,大多情况下读操作在主节点,如果主节点不可用,如故障转移,读操作在从节点。
3)secondary:从节点,读操作只在从节点, 如果从节点不可用,报错或者抛出异常。
4)secondaryPreferred:首选从节点,大多情况下读操作在从节点,特殊情况(如单主节点架构)读操作在主节点。
5)nearest:最邻近节点,读操作在最邻近的成员,可能是主节点或者从节点。
*/.
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
ErrDryRunModeUnsupported dry run mode unsupported.
ErrEmptySlice empty slice found.
No description provided by the author
ErrInvalidData unsupported data.
ErrInvalidDB invalid db.
ErrInvalidField invalid field.
No description provided by the author
ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`.
ErrInvalidValue invalid value.
ErrInvalidValueOfLength invalid values do not match length.
ErrMissingWhereClause missing where clause.
ErrModelValueRequired model value required.
ErrNotImplemented not implemented.
No description provided by the author
ErrPrimaryKeyRequired primary keys required.
ErrRegistered registered.
No description provided by the author
ErrUnsupportedDriver unsupported driver.
ErrUnsupportedRelation unsupported relations.