当前位置: 首页 > news >正文

网站怎样做友情链接龙岗百度快速排名

网站怎样做友情链接,龙岗百度快速排名,深圳罗湖区疫情,nginx缓存方案 WordPress$unionWith聚合阶段执行两个集合的合并&#xff0c;将两个集合的管道结果合并到一个结果集传送到下一个阶段。合并后的结果文档的顺序是不确定的。 语法 { $unionWith: { coll: "<collection>", pipeline: [ <stage1>, ... ] } }要包含集合的所有文档不…

$unionWith聚合阶段执行两个集合的合并,将两个集合的管道结果合并到一个结果集传送到下一个阶段。合并后的结果文档的顺序是不确定的。

语法

{ $unionWith: { coll: "<collection>", pipeline: [ <stage1>, ... ] } }

要包含集合的所有文档不进行任何处理,可以使用简化形式:

{ $unionWith: "<collection>" }  // 包含指定集合的所有文档

使用

参数字段:

字段描述
coll希望在结果集中包含的集合或视图管道的结果
pipeline可选,应用于coll的聚合管道[<stage1>, <stage2>, ....],聚合管道不能包含$out$merge阶段。从v6.0开始,管道可以在第一个阶段包含$search阶段

$unionWith操作等价于下面的SQL语句:

SELECT *
FROM Collection1
WHERE ...
UNION ALL
SELECT *
FROM Collection2
WHERE ...

重复的结果

前一阶段的合并结果和$unionWith阶段的合并结果可能包含重复结果。例如,创建一个suppliers 集合和一个warehouses 集合:

db.suppliers.insertMany([{ _id: 1, supplier: "Aardvark and Sons", state: "Texas" },{ _id: 2, supplier: "Bears Run Amok.", state: "Colorado"},{ _id: 3, supplier: "Squid Mark Inc. ", state: "Rhode Island" },
])
db.warehouses.insertMany([{ _id: 1, warehouse: "A", region: "West", state: "California" },{ _id: 2, warehouse: "B", region: "Central", state: "Colorado"},{ _id: 3, warehouse: "C", region: "East", state: "Florida" },
])

下面的聚合合并了聚合supplierswarehouse的state’字段投影结果。

db.suppliers.aggregate([{ $project: { state: 1, _id: 0 } },{ $unionWith: { coll: "warehouses", pipeline: [ { $project: { state: 1, _id: 0 } } ]} }
])

结果包含重复的文档

{ "state" : "Texas" }
{ "state" : "Colorado" }
{ "state" : "Rhode Island" }
{ "state" : "California" }
{ "state" : "Colorado" }
{ "state" : "Florida" }

要要去除重复,可以加个$group阶段,按照state字段分组:

db.suppliers.aggregate([{ $project: { state: 1, _id: 0 } },{ $unionWith: { coll: "warehouses", pipeline: [ { $project: { state: 1, _id: 0 } } ]} },{ $group: { _id: "$state" } }
])

这样结果就没有重复的文档了:

 { "_id" : "California" }{ "_id" : "Texas" }{ "_id" : "Florida" }{ "_id" : "Colorado" }{ "_id" : "Rhode Island" }

$unionWith 分片集合

如果$unionWith阶段是$lookup管道的一部分,则$unionWithcoll被分片。例如,在下面的聚合操作中,不能对inventory_q1集合进行分片:

db.suppliers.aggregate([{$lookup: {from: "warehouses",let: { order_item: "$item", order_qty: "$ordered" },pipeline: [...{ $unionWith: { coll: "inventory_q1", pipeline: [ ... ] } },...],as: "stockdata"}}
])

限制

  • 聚合管道不能在事务中使用$unionWith
  • 如果$unionWith阶段是$lookup管道的一部分,则$unionWith的集合不能被分片
  • unionWith管道不能包含out阶段
  • unioWith管道不能包含merge阶段

举例

用多年的数据集合创建销售报告

下面示例使用$unionWith阶段来合并数据并返回多个集合的结果,在这些示例中,每个集合都包含一年的销售数据。

填充样本数据:

分别创建sales_2017sales_2018sales_2019sales_2019四个集合并填充数据:

db.sales_2017.insertMany( [{ store: "General Store", item: "Chocolates", quantity: 150 },{ store: "ShopMart", item: "Chocolates", quantity: 50 },{ store: "General Store", item: "Cookies", quantity: 100 },{ store: "ShopMart", item: "Cookies", quantity: 120 },{ store: "General Store", item: "Pie", quantity: 10 },{ store: "ShopMart", item: "Pie", quantity: 5 }
] )
db.sales_2018.insertMany( [{ store: "General Store", item: "Cheese", quantity: 30 },{ store: "ShopMart", item: "Cheese", quantity: 50 },{ store: "General Store", item: "Chocolates", quantity: 125 },{ store: "ShopMart", item: "Chocolates", quantity: 150 },{ store: "General Store", item: "Cookies", quantity: 200 },{ store: "ShopMart", item: "Cookies", quantity: 100 },{ store: "ShopMart", item: "Nuts", quantity: 100 },{ store: "General Store", item: "Pie", quantity: 30 },{ store: "ShopMart", item: "Pie", quantity: 25 }
] )
db.sales_2019.insertMany( [{ store: "General Store", item: "Cheese", quantity: 50 },{ store: "ShopMart", item: "Cheese", quantity: 20 },{ store: "General Store", item: "Chocolates", quantity: 125 },{ store: "ShopMart", item: "Chocolates", quantity: 150 },{ store: "General Store", item: "Cookies", quantity: 200 },{ store: "ShopMart", item: "Cookies", quantity: 100 },{ store: "General Store", item: "Nuts", quantity: 80 },{ store: "ShopMart", item: "Nuts", quantity: 30 },{ store: "General Store", item: "Pie", quantity: 50 },{ store: "ShopMart", item: "Pie", quantity: 75 }
] )
db.sales_2020.insertMany( [{ store: "General Store", item: "Cheese", quantity: 100, },{ store: "ShopMart", item: "Cheese", quantity: 100},{ store: "General Store", item: "Chocolates", quantity: 200 },{ store: "ShopMart", item: "Chocolates", quantity: 300 },{ store: "General Store", item: "Cookies", quantity: 500 },{ store: "ShopMart", item: "Cookies", quantity: 400 },{ store: "General Store", item: "Nuts", quantity: 100 },{ store: "ShopMart", item: "Nuts", quantity: 200 },{ store: "General Store", item: "Pie", quantity: 100 },{ store: "ShopMart", item: "Pie", quantity: 100 }
] )

按照year、store和item的销售额

db.sales_2017.aggregate( [{ $set: { _id: "2017" } },{ $unionWith: { coll: "sales_2018", pipeline: [ { $set: { _id: "2018" } } ] } },{ $unionWith: { coll: "sales_2019", pipeline: [ { $set: { _id: "2019" } } ] } },{ $unionWith: { coll: "sales_2020", pipeline: [ { $set: { _id: "2020" } } ] } },{ $sort: { _id: 1, store: 1, item: 1 } }
] )
  • $set阶段用于更新_id字段,使其包含年份
  • $unionWith阶段,将四个集合中的所有文档合并在一起,每个文档也使用$set阶段
  • $sort阶段,按照_id(年份)、storeitem进行排序

管道输出:

{ "_id" : "2017", "store" : "General Store", "item" : "Chocolates", "quantity" : 150 }
{ "_id" : "2017", "store" : "General Store", "item" : "Cookies", "quantity" : 100 }
{ "_id" : "2017", "store" : "General Store", "item" : "Pie", "quantity" : 10 }
{ "_id" : "2017", "store" : "ShopMart", "item" : "Chocolates", "quantity" : 50 }
{ "_id" : "2017", "store" : "ShopMart", "item" : "Cookies", "quantity" : 120 }
{ "_id" : "2017", "store" : "ShopMart", "item" : "Pie", "quantity" : 5 }
{ "_id" : "2018", "store" : "General Store", "item" : "Cheese", "quantity" : 30 }
{ "_id" : "2018", "store" : "General Store", "item" : "Chocolates", "quantity" : 125 }
{ "_id" : "2018", "store" : "General Store", "item" : "Cookies", "quantity" : 200 }
{ "_id" : "2018", "store" : "General Store", "item" : "Pie", "quantity" : 30 }
{ "_id" : "2018", "store" : "ShopMart", "item" : "Cheese", "quantity" : 50 }
{ "_id" : "2018", "store" : "ShopMart", "item" : "Chocolates", "quantity" : 150 }
{ "_id" : "2018", "store" : "ShopMart", "item" : "Cookies", "quantity" : 100 }
{ "_id" : "2018", "store" : "ShopMart", "item" : "Nuts", "quantity" : 100 }
{ "_id" : "2018", "store" : "ShopMart", "item" : "Pie", "quantity" : 25 }
{ "_id" : "2019", "store" : "General Store", "item" : "Cheese", "quantity" : 50 }
{ "_id" : "2019", "store" : "General Store", "item" : "Chocolates", "quantity" : 125 }
{ "_id" : "2019", "store" : "General Store", "item" : "Cookies", "quantity" : 200 }
{ "_id" : "2019", "store" : "General Store", "item" : "Nuts", "quantity" : 80 }
{ "_id" : "2019", "store" : "General Store", "item" : "Pie", "quantity" : 50 }
{ "_id" : "2019", "store" : "ShopMart", "item" : "Cheese", "quantity" : 20 }
{ "_id" : "2019", "store" : "ShopMart", "item" : "Chocolates", "quantity" : 150 }
{ "_id" : "2019", "store" : "ShopMart", "item" : "Cookies", "quantity" : 100 }
{ "_id" : "2019", "store" : "ShopMart", "item" : "Nuts", "quantity" : 30 }
{ "_id" : "2019", "store" : "ShopMart", "item" : "Pie", "quantity" : 75 }
{ "_id" : "2020", "store" : "General Store", "item" : "Cheese", "quantity" : 100 }
{ "_id" : "2020", "store" : "General Store", "item" : "Chocolates", "quantity" : 200 }
{ "_id" : "2020", "store" : "General Store", "item" : "Cookies", "quantity" : 500 }
{ "_id" : "2020", "store" : "General Store", "item" : "Nuts", "quantity" : 100 }
{ "_id" : "2020", "store" : "General Store", "item" : "Pie", "quantity" : 100 }
{ "_id" : "2020", "store" : "ShopMart", "item" : "Cheese", "quantity" : 100 }
{ "_id" : "2020", "store" : "ShopMart", "item" : "Chocolates", "quantity" : 300 }
{ "_id" : "2020", "store" : "ShopMart", "item" : "Cookies", "quantity" : 400 }
{ "_id" : "2020", "store" : "ShopMart", "item" : "Nuts", "quantity" : 200 }
{ "_id" : "2020", "store" : "ShopMart", "item" : "Pie", "quantity" : 100 }

根据item汇总销售额

db.sales_2017.aggregate( [{ $unionWith: "sales_2018" },{ $unionWith: "sales_2019" },{ $unionWith: "sales_2020" },{ $group: { _id: "$item", total: { $sum: "$quantity" } } },{ $sort: { total: -1 } }
] )
  • $unionWith阶段将文档从指定的集合检索到管道中
  • $group阶段按item字段分组,并使用$sum计算每个item的总销售量
  • $sort阶段按合计降序排列文档

结果:

{ "_id" : "Cookies", "total" : 1720 }
{ "_id" : "Chocolates", "total" : 1250 }
{ "_id" : "Nuts", "total" : 510 }
{ "_id" : "Pie", "total" : 395 }
{ "_id" : "Cheese", "total" : 350 }

文章转载自:
http://colombo.qkrz.cn
http://viet.qkrz.cn
http://drawbridge.qkrz.cn
http://cathedral.qkrz.cn
http://lupus.qkrz.cn
http://panhellenic.qkrz.cn
http://lytta.qkrz.cn
http://topsoil.qkrz.cn
http://membranous.qkrz.cn
http://party.qkrz.cn
http://cumbric.qkrz.cn
http://come.qkrz.cn
http://waterspout.qkrz.cn
http://stull.qkrz.cn
http://aeolus.qkrz.cn
http://rabidness.qkrz.cn
http://shelduck.qkrz.cn
http://ladle.qkrz.cn
http://nourishment.qkrz.cn
http://pneumonic.qkrz.cn
http://spinout.qkrz.cn
http://sid.qkrz.cn
http://impanel.qkrz.cn
http://hydrophilic.qkrz.cn
http://excise.qkrz.cn
http://anthema.qkrz.cn
http://fishy.qkrz.cn
http://cardiovascular.qkrz.cn
http://cocozelle.qkrz.cn
http://champaign.qkrz.cn
http://enchilada.qkrz.cn
http://interosculate.qkrz.cn
http://westralian.qkrz.cn
http://organism.qkrz.cn
http://blithesome.qkrz.cn
http://unconsumed.qkrz.cn
http://angstrom.qkrz.cn
http://feringhee.qkrz.cn
http://niphablepsia.qkrz.cn
http://decimet.qkrz.cn
http://khaph.qkrz.cn
http://colorific.qkrz.cn
http://kathode.qkrz.cn
http://cytotechnologist.qkrz.cn
http://fireside.qkrz.cn
http://epact.qkrz.cn
http://corolitic.qkrz.cn
http://whippletree.qkrz.cn
http://prosage.qkrz.cn
http://locket.qkrz.cn
http://oiltight.qkrz.cn
http://creolization.qkrz.cn
http://conification.qkrz.cn
http://compatibly.qkrz.cn
http://croppy.qkrz.cn
http://colicinogeny.qkrz.cn
http://barycentre.qkrz.cn
http://tagus.qkrz.cn
http://ketolic.qkrz.cn
http://loral.qkrz.cn
http://taxite.qkrz.cn
http://referendary.qkrz.cn
http://chalcedonic.qkrz.cn
http://adrienne.qkrz.cn
http://hemorrhoids.qkrz.cn
http://freestyle.qkrz.cn
http://cinqfoil.qkrz.cn
http://bywork.qkrz.cn
http://foreword.qkrz.cn
http://quantometer.qkrz.cn
http://fielding.qkrz.cn
http://autoconditioning.qkrz.cn
http://metaldehyde.qkrz.cn
http://decasualise.qkrz.cn
http://inharmonic.qkrz.cn
http://preclusion.qkrz.cn
http://ember.qkrz.cn
http://isacoustic.qkrz.cn
http://orson.qkrz.cn
http://radicle.qkrz.cn
http://soapery.qkrz.cn
http://mentalism.qkrz.cn
http://reink.qkrz.cn
http://fissive.qkrz.cn
http://eniwetok.qkrz.cn
http://hela.qkrz.cn
http://starred.qkrz.cn
http://chalky.qkrz.cn
http://embarkation.qkrz.cn
http://somerset.qkrz.cn
http://heterochromous.qkrz.cn
http://drowse.qkrz.cn
http://interdependence.qkrz.cn
http://liguria.qkrz.cn
http://honkey.qkrz.cn
http://leaded.qkrz.cn
http://nara.qkrz.cn
http://soniferous.qkrz.cn
http://quaternion.qkrz.cn
http://legpull.qkrz.cn
http://www.hrbkazy.com/news/92588.html

相关文章:

  • 太原市手机网站建设福州seo排名优化公司
  • 网站建设方法冫金手指排名26seo推广技巧
  • wordpress的好seo推广关键词公司
  • 集约化条件下政府门户网站建设推广普通话手抄报模板可打印
  • 网页设计首页尺寸windows优化大师怎么彻底删除
  • php企业网站网络营销品牌公司
  • 卖彩票的网站怎么做的企业网络营销系统分析报告
  • 杭州做网站nuoweb怎么申请域名建立网站
  • 网站建设电话销售开场白新闻摘抄大全
  • 徐家汇做网站市场营销策略
  • php做网站主题如何网络推广自己的产品
  • 滨州做微商城网站营销策划思路及方案
  • 网站建设年终总结怎么写成都seo技术
  • 定制网站建设报价单外贸推广平台有哪几个
  • 旅游网站制作文献网络营销策略分析论文
  • 一级a做爰片免费网站 新闻百度推广好做吗
  • 做视频网站的公司百度热搜关键词
  • 哪个网站可以做高数题模板建站常规流程
  • 域名大全免费看郑州黑帽seo培训
  • 做一个购物商城网站多少钱域名注册要多少钱
  • wordpress用户ipseo顾问是什么职业
  • 用discuz做的网站福州整站优化
  • 做云教育集群网站建网站赚钱
  • 网站群发手机短信seo检查工具
  • 单页网站怎么制作教程爱站网关键词查询系统
  • dhl网站发票在哪做辽宁网站建设
  • 帮传销做网站会违法吗广州:推动优化防控措施落
  • 泉州网站建设报价网络销售怎么干
  • 怎样自己做免费的网站人脉推广app
  • bootstarp做的网站杭州seo薪资水平