当前位置:网站首页>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 |
边栏推荐
- How vivado adds timing constraints
- 【剑指Offer】48. 最长不含重复字符的子字符串
- 消除el-image图片周围间隙
- How to set the enterprise wechat group robots to send messages regularly?
- EasyCVR平台路由日志功能的技术实现过程【附代码】
- 通过中金证券经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- PAT乙级1013
- 用pytorch进行CIFAR-10数据集分类
- How to solve the problem that the browser developed with CeF3 does not support flash
- 【Vim】使用教程,常用命令,高效使用Vim编辑器
猜你喜欢

一文剖析C语言函数

ASP.NET仓库进销存ERP管理系统源码 ERP小程序源码

Golang - the difference between new and make

Small chip chiplet Technology

实践torch.fx:基于Pytorch的模型优化量化神器

EasyCVR平台路由日志功能的技术实现过程【附代码】

电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!

VMware virtual machine bridging connectivity

fiddler 监听不到接口怎么办

零基础自学SQL课程 | IF函数
随机推荐
量化交易入门教程
Technical implementation process of easycvr platform routing log function [code attached]
Classification of cifar-10 dataset with pytorch
沉寂了一段时间 ,我又出来啦~
Introduction to quantitative trading
零基础自学SQL课程 | SQL基本函数大全
Structure de stockage des graphiques
【tinyriscv verilator】分支移植到正点原子达芬奇开发板
Getting started with pytorch
Cornernet由浅入深理解
SQL中IS NOT NULL与!=NULL的区别
Discuz small fish game wind shadow legend business gbk+utf8 version template /dz game website template
Working at home is more tiring than going to work at the company?
Halcon's region: features of multiple regions (6)
Use of go log package log
golang - new和make的区别
支持删除,更新任意结点的优先级队列
First principles (optimal solution theory)
文献综述如何挑选文献进行阅读,比如我的检索结果有200多篇根本看不完,如何进行文献挑选呢?...
How vivado adds timing constraints