-
Notifications
You must be signed in to change notification settings - Fork 155
Differences between Qmgo and Mgo
jiangz222 edited this page Dec 1, 2020
·
7 revisions
About initial configuration, qmgo
will refer to some of the official mongoDB driver
, such as using ReadPref
instead of Mgo
's Mode
cfg = Config{
Uri: "mongodb://localhost:27017",
Database: "user",
Coll: "classs",
ReadPreference: &ReadPref{Mode: readpref.SecondaryMode, MaxStalenessMS: 500},
}
cli, err := Open(context.Background(), &cfg)
-
Most API need
Context
as parameter -
Different implement about
ObjectId
,for example,ObjectId
is string in mgo and [12]byte in qmgo -
Update interfaces(UpdateOne、UpdateAll...) must contain key beginning with '$': Following codes are illegal in
qmgo
orofficial mongoDB driver
, which is legal inmgo
filter := bson.M{
"name": "Alice",
}
update := bson.M{
// "$set": bson.M{ // this is required in qmgo or official mongoDB driver, not required in mgo
"name": "Alice1",
"age": 18,
// },
}
err = cli.UpdateOne(context.Background(), filter, update)
- The name of interface
Update(...) -> UpdateOne(...)
Insert(...) -> InsertOne(...)
- Insert uint32 data become BSON int64 in MongoDB, sometimes cause error when consume it.
- Issue in qmgo.
- Issut to fix the difference when call distinct().
- Issue in Mongo-official-driver.
- Before official MongoDB driver fix it, you can update (or insert) bson:"foo" tags to look like bson:"foo,minsize".
- Mgo will initial the field to default value of Go when it's not initialed, Qmgo will not.
For example, if you insert a field of slice type without initialization, it is
[]
in mongoDB when use Mgo, andnull
when use Qmgo https://github.com/qiniu/qmgo/issues/117