Documentation ¶
Index ¶
- Variables
- func Connect(mongoUrl string) (*mongo.Client, error)
- type Collection
- func (c *Collection) Coll() *mongo.Collection
- func (c *Collection) CountDocuments(filter any) (int64, error)
- func (coll *Collection) CreateIndex(list []*Index) ([]string, error)
- func (coll *Collection) CreateIndexByKeys(keys ...string)
- func (c *Collection) DeleteId(id any) error
- func (c *Collection) DeleteOne(filter any) error
- func (c *Collection) Exists(filter bson.M) (bool, error)
- func (c *Collection) FindAll(filter bson.M, doc any) error
- func (c *Collection) FindAllOpt(filter bson.M, doc any, opt *options.FindOptions) error
- func (c *Collection) FindId(id, doc any) error
- func (c *Collection) FindOne(filter, doc any) error
- func (c *Collection) FindPage(args FindPageOpt, doc any) (count int64, err error)
- func (c *Collection) FindPageFakeCount(args FindPageOpt, doc any) (count int64, err error)
- func (c *Collection) InsertOne(doc any) error
- func (c *Collection) Update(filter any, update any) error
- func (c *Collection) UpdateId(id any, update any) error
- func (c *Collection) UpdateOne(id any, update any) error
- func (c *Collection) Upsert(filter any, update any) error
- func (c *Collection) UpsertId(id any, update any) error
- func (c *Collection) UpsertOne(filter any, update any) error
- type DB
- type DocOf
- type FindPageOpt
- type Index
- type IndexOrder
- type ObjectID
- func (*ObjectID) Descriptor() ([]byte, []int)deprecated
- func (id *ObjectID) Hex() string
- func (id *ObjectID) MarshalJSON() ([]byte, error)
- func (*ObjectID) ProtoMessage()
- func (x *ObjectID) ProtoReflect() protoreflect.Message
- func (x *ObjectID) Reset()
- func (x *ObjectID) String() string
- func (id *ObjectID) UnmarshalJSON(b []byte) error
- type ObjectIDCodec
- type TimeStamp
- func (x *TimeStamp) AsTime() time.Time
- func (*TimeStamp) Descriptor() ([]byte, []int)deprecated
- func (x *TimeStamp) GetNanos() int32
- func (x *TimeStamp) GetSeconds() int64
- func (x *TimeStamp) MarshalJSON() ([]byte, error)
- func (*TimeStamp) ProtoMessage()
- func (x *TimeStamp) ProtoReflect() protoreflect.Message
- func (x *TimeStamp) Reset()
- func (x *TimeStamp) SetTime(t time.Time)
- func (x *TimeStamp) String() string
- func (x *TimeStamp) UnmarshalJSON(b []byte) error
- type TimeStampCodec
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultRegistry = build()
View Source
var File_pb_ObjectID_proto protoreflect.FileDescriptor
View Source
var File_pb_TimeStamp_proto protoreflect.FileDescriptor
Functions ¶
Types ¶
type Collection ¶
type Collection struct { Name string // contains filtered or unexported fields }
func (*Collection) Coll ¶
func (c *Collection) Coll() *mongo.Collection
func (*Collection) CountDocuments ¶
func (c *Collection) CountDocuments(filter any) (int64, error)
统计满足条件的文档数,会遍历整个表 判断条件是否存在请使用 Exists
func (*Collection) CreateIndex ¶
func (coll *Collection) CreateIndex(list []*Index) ([]string, error)
创建索引,不支持联合索引
func (*Collection) CreateIndexByKeys ¶
func (coll *Collection) CreateIndexByKeys(keys ...string)
偷懒写法
func (*Collection) DeleteId ¶
func (c *Collection) DeleteId(id any) error
func (*Collection) DeleteOne ¶
func (c *Collection) DeleteOne(filter any) error
func (*Collection) FindAllOpt ¶
func (c *Collection) FindAllOpt(filter bson.M, doc any, opt *options.FindOptions) error
func (*Collection) FindId ¶
func (c *Collection) FindId(id, doc any) error
func (*Collection) FindOne ¶
func (c *Collection) FindOne(filter, doc any) error
func (*Collection) FindPage ¶
func (c *Collection) FindPage(args FindPageOpt, doc any) (count int64, err error)
func (*Collection) FindPageFakeCount ¶
func (c *Collection) FindPageFakeCount(args FindPageOpt, doc any) (count int64, err error)
返回假的count,避免用时过长
func (*Collection) InsertOne ¶
func (c *Collection) InsertOne(doc any) error
type DB ¶
func (*DB) Collection ¶
func (db *DB) Collection(collName string) *Collection
type DocOf ¶
type DocOf[K ut2.Comparable, V any] struct { Coll *Collection Ctor func(*V) // 在自动创建的时候调用,初始化数据 Map ut2.IMap[K, *V] // contains filtered or unexported fields }
管理一张Mongo表。 并支持内存中缓存。自动以 _id 为 Key
func NewDocOfWith ¶
func NewDocOfWith[K ut2.Comparable, V any](coll *Collection, mp ut2.IMap[K, *V]) *DocOf[K, V]
func NewDocOfWithoutCache ¶
func NewDocOfWithoutCache[K ut2.Comparable, V any](coll *Collection) *DocOf[K, V]
无 内存缓存
type FindPageOpt ¶
type Index ¶
type Index struct { Key string Background bool SetUnique bool Sparse bool Order IndexOrder }
type IndexOrder ¶
type IndexOrder int32
const ( IndexAscending IndexOrder = 0 // 升序 = 1 默认 IndexDescending = 1 // 降序 = -1 )
type ObjectID ¶
type ObjectID struct { Data []byte `protobuf:"bytes,1,opt,name=Data,proto3" ` // contains filtered or unexported fields }
func NewObjectID ¶
func NewObjectID() *ObjectID
func ObjectIDFromHex ¶
func (*ObjectID) Descriptor
deprecated
func (*ObjectID) MarshalJSON ¶
func (*ObjectID) ProtoMessage ¶
func (*ObjectID) ProtoMessage()
func (*ObjectID) ProtoReflect ¶
func (x *ObjectID) ProtoReflect() protoreflect.Message
func (*ObjectID) UnmarshalJSON ¶
type ObjectIDCodec ¶
type ObjectIDCodec struct{}
func (*ObjectIDCodec) DecodeValue ¶
func (tc *ObjectIDCodec) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
DecodeValue is the ValueDecoderFunc for time.Time.
func (*ObjectIDCodec) EncodeValue ¶
func (tc *ObjectIDCodec) EncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error
EncodeValue is the ValueEncoderFunc for time.TIme.
type TimeStamp ¶
type TimeStamp struct { Seconds int64 `protobuf:"varint,1,opt,name=Seconds,proto3" ` Nanos int32 `protobuf:"varint,2,opt,name=Nanos,proto3" ` // contains filtered or unexported fields }
func NewTimeStamp ¶
New constructs a new Timestamp from the provided time.Time.
func (*TimeStamp) Descriptor
deprecated
func (*TimeStamp) GetSeconds ¶
func (*TimeStamp) MarshalJSON ¶
func (*TimeStamp) ProtoMessage ¶
func (*TimeStamp) ProtoMessage()
func (*TimeStamp) ProtoReflect ¶
func (x *TimeStamp) ProtoReflect() protoreflect.Message
func (*TimeStamp) UnmarshalJSON ¶
type TimeStampCodec ¶
type TimeStampCodec struct{}
func (*TimeStampCodec) DecodeValue ¶
func (tc *TimeStampCodec) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
DecodeValue is the ValueDecoderFunc for time.Time.
func (*TimeStampCodec) EncodeValue ¶
func (tc *TimeStampCodec) EncodeValue(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, val reflect.Value) error
EncodeValue is the ValueEncoderFunc for time.TIme.
Click to show internal directories.
Click to hide internal directories.