[Mongo] Mongo Go Driver
官方文件
Quick Reference:列出常用的 CRUD 語法
CRUD
官方文件
READ
官方文件
Operators
comparison operators
func main() {
// ...
filter := bson.D{{"runtime", bson.D{{"$ne", 60}}}}
filter := bson.D{{"rating.average", bson.D{{"$gte", 7.9}}}}
filter := bson.D{{"genres", "Drama"}}
filter := bson.D{{"genres", bson.A{"Drama"}}}
filter := bson.D{{"runtime", bson.D{{"$nin", bson.A{30, 42}}}}}
cursor, err := coll.Find(ctx, filter)
// ...
}
logical operators
func main() {
// ...
filter := bson.D{{"$nor", bson.A{
bson.D{{"rating.average", bson.D{{"$lt", 5}}}},
bson.D{{"rating.average", bson.D{{"$gt", 9.3}}}},
}}}
filter := bson.D{{"$and", bson.A{
bson.D{{"rating.average", bson.D{{"$gt", 9}}}},
bson.D{{"genres", "Drama"}},
}}}
filter := bson.D{{"genres", "Drama"}, {"genres", "Horror"}}
filter := bson.D{{"runtime", bson.D{{"$not", bson.D{{"$eq", 60}}}}}}
cursor, err := coll.Find(ctx, filter)
// ...
}