当前位置:网站首页>Golang uses Mongo driver operation - query (Advanced)
Golang uses Mongo driver operation - query (Advanced)
2022-06-27 23:43:00 【lsjweiyi】
For more complex queries, I can't think of any occasion to use them , So I will add it slowly when I have it .
and and or Combine :
// Show complex and and or Relation combination query
func AdvanceAndOr(mongo *mongo.Database, ctx context.Context) {
// Usually our conditions are implicit and Relationship , But because it needs to be used twice at the same time $or, So it is necessary to display and use and
filter := bson.M{
"$and": bson.A{
bson.M{
"$or": bson.A{
bson.M{
"int32": math.MaxInt32}, bson.M{
"int32": math.MaxInt32 - 1}}}, bson.M{
"$or": bson.A{
bson.M{
"boolean": true}, bson.M{
"boolean": false}}}}}
// Query data , And parse it into a structure
cur, _ := mongo.Collection("test").Find(ctx, filter)
// Traversal data
for cur.TryNext(ctx) {
result, _ := cur.Current.Elements()
fmt.Println(result)
}
cur.Close(ctx)
}
In my opinion, complex queries are often combined with various keywords , therefore , Here are some keywords that have not been practiced , For future reference .
| keyword | explain | link |
|---|---|---|
| ne | It's not equal to | link |
| not | Reverse results , All documents except matching criteria | link |
| nor | Return documents that do not match each condition or do not have this field , It's very similar to the one above , But there's a difference | link |
| exists | Documents with specified fields | link |
| type | Match field type | link |
| expr | Aggregate expression , It's very powerful , Very complicated | link |
| jsonSchema | Document verification rules , The data of the document itself has no restrictions , Use this to limit | link |
| mod | modulus , Use remainder as query condition | link |
| regex | Regular Expression Matching | link |
| text Text search , But you need to build an index , impractical | link |
边栏推荐
猜你喜欢
随机推荐
零基础自学SQL课程 | IF函数
跨系统数据一致性问题解决方案汇总
Usage of vivado vio IP
量化交易入门教程
【PCL自学:Segmentation3】基于PCL的点云分割:区域增长分割
【AI应用】NVIDIA Tesla V100S-PCIE-32GB的详情参数
【蓝桥杯集训100题】scratch数字计算 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第16题
搭建开源美观的数据库监控系统-Lepus
企业架构师面试的100个问题
Excel print settings public header
Classification of cifar-10 dataset with pytorch
最新云开发微信余额充电器特效小程序源码
通过中金证券经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
Detailed explanation of MATLAB axis coordinate axis related settings
const关键字及其作用(用法),C语言const详解
Online JSON to plaintext tool
PAT乙级1013
Teach you how to transplant tinyriscv to FPGA
seata
Swing UI container (I)






