使用嵌套子文档的$ unwind(Using $unwind with nested subdocuments)
我有一个具有以下结构的集合:
{ { node: 'ST20' Ds:{ 699:{ TotCM: 300 Docsis20: 200 Docsis30: 100 } 705:{ TotCM: 250 Docsis20: 150 Docsis30: 100 } } } { node: 'ST21' Ds:{ 651:{ TotCM: 200 Docsis20: 100 Docsis30: 100 } 699:{ TotCM: 100 Docsis20: 0 Docsis30: 100 } } } }
如您所见,我有一个代表节点的文档。 每个节点都有不同的通道。 我的目标是看看每个频道有多少个有线电视。 从前面开始,我不知道每个节点中的通道。 所以我希望有这样的东西:
{ node: 'ST20', Ds: 699, TotCM: 300, Docsis20: 200, Docsis30:100 } { node: 'ST20', Ds: 705, TotCM: 250, Docsis20: 150, Docsis30:100 } { node: 'ST21', Ds: 651, TotCM: 200, Docsis20: 100, Docsis30:100 } { node: 'ST21', Ds: 699, TotCM: 100, Docsis20: 0, Docsis30:100 }
我尝试了以下查询:
db.statsNodos.aggregate( { $project: {_id:0,Ds:1,node:1}}, { $unwind: "$Ds"} ).pretty()
但是我得到了原始文件。 而且,正如您所看到的,它们是嵌套文档而不是文档数组。 也许我不必使用
$unwind
,还有另一种方法可以解决这个问题。 你能告诉我吗?I have a collection with the following structure:
{ { node: 'ST20' Ds:{ 699:{ TotCM: 300 Docsis20: 200 Docsis30: 100 } 705:{ TotCM: 250 Docsis20: 150 Docsis30: 100 } } } { node: 'ST21' Ds:{ 651:{ TotCM: 200 Docsis20: 100 Docsis30: 100 } 699:{ TotCM: 100 Docsis20: 0 Docsis30: 100 } } } }
As you can see, I have a document that represents a node. Each node, has different channels. My objective is see how many cablemodems I have in each channel. From upfront, I don't know the channels that I have in each node. So I would like to have something like this:
{ node: 'ST20', Ds: 699, TotCM: 300, Docsis20: 200, Docsis30:100 } { node: 'ST20', Ds: 705, TotCM: 250, Docsis20: 150, Docsis30:100 } { node: 'ST21', Ds: 651, TotCM: 200, Docsis20: 100, Docsis30:100 } { node: 'ST21', Ds: 699, TotCM: 100, Docsis20: 0, Docsis30:100 }
I tried the following query:
db.statsNodos.aggregate( { $project: {_id:0,Ds:1,node:1}}, { $unwind: "$Ds"} ).pretty()
But I get the original document. And, as you can see, they are nested documents and not an array of documents. Maybe I don't have to use
$unwind
and there is another way to get this. Can you tell me?
原文:https://stackoverflow.com/questions/46286550
满意答案
这是因为您需要对click事件应用更改。 因此,您可以添加此代码以在每次单击章节时调整视频大小(您可以添加一些延迟以确保获得正确的大小):
$('ul.nav-tabs a').click(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); });
您还可以使用
$(document).ready
函数,以确保调整大小代码在页面加载时运行良好。完整代码:
$(document).ready(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); $(window).resize(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }); $('ul.nav-tabs a').click(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); }); });
/* Tools */ .no-padding { padding: 0!important; } .slow-effect { transition: all .2s ease-in-out; -webkit-transition: all .2s ease-in-out; } /* ======================================================================================= */ /* Layout ================================================================================ */ .space { height: 50px; } .container-fluid { padding: 0 4%; } /* Global Styles ========================================================================= */ /* Form Elements */ /*start places*/ body { height: 2000px; } .main-container { border: 2px solid #000; overflow: hidden; } .description { background-color: #898989; padding: 16px 30px; overflow: auto; } .description ul { margin: 0; padding: 0; } .description ul li a { background-color: #898989; color: #fff; padding-bottom: 18px; margin-bottom: 18px; position: relative; border: none; } .nav-tabs>li>a:hover { border: none; border-bottom: 2px solid #fff; background-color: #fff; color: #555555; } .description ul li a>h2 { font-weight: 700; font-size: 35px; margin: 0; } .description ul li a>p { font-size: 18px; line-height: 30px; margin-top: 5px; margin-bottom: 0; } .video-container { position: relative; } .video-container .tools { position: absolute; width: 100%; height: 40px; background-color: #a4a4a4; left: 0; bottom: 0; z-index: 999; } .video-container:hover .tools { visibility: hidden; } #style-1::-webkit-scrollbar { background-color: #898989; } #style-1::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .3); background-color: #adadad } #style-1::-webkit-scrollbar { width: 20px; } @media(min-width: 992px) { .description { border-left: 2px solid #000; } .description ul li a { border-bottom: 2px solid #fff; } } @media(max-width: 991px) { .description { border-left: 2px solid #000; white-space: nowrap; padding: 0; height: auto!important; } .description ul li a { display: inline-block; width: 34%; padding: 14px; text-align: left; overflow: hidden; min-height: 252px; white-space: normal; vertical-align: text-top; margin-bottom: 0; } .description ul li:after { content: ""; display: inline-block; width: 2px; height: 170px; position: absolute; right: 6px; top: 20px; background-color: #fff; } .description ul li:last-child:after { content: ""; display: none; } .description ul li a>h2 { font-size: 22px; } .description ul li a>p { font-size: 14px; line-height: 23px; } } @media screen and (min-width: 220px) and (max-width: 550px) { .description ul li a { padding: 8px; min-height: 200px; } .description ul li a h2 { font-size: 14px; } .description ul li a p { font-size: 10px; line-height: 16px; } }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container-fluid"> <div class="row"> <div class="space"></div> <div id="exTab2" class="col-xs-12 no-padding main-container"> <div class="col-md-9 no-padding video-container tab-content"> <div id="1" class="tabs-container tab-pane fade in active"> <!-- Item-1 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> <source src="test.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> <div id="2" class="tabs-container tab-pane fade"> <!-- Item-2 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="https://www.w3schools.com/html/movie.mp4" type="video/mp4"> <source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> <div id="3" class="tabs-container tab-pane fade"> <!-- Item-3 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> <div id="4" class="tabs-container tab-pane fade"> <!-- Item-4 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="test.WEBM" type="video/mp4"> <source src="test.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> </div> <!-- Item-2 --> <div class="col-md-3 description" id="style-1"> <ul class="nav nav-tabs"> <li class="active"> <a data-toggle="tab" href="#1"> <h2>Chapter 1</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit, illo vel neque sunt doloremque incidunt.</p> </a> </li> <li> <a data-toggle="tab" href="#2"> <h2>Chapter 2</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit, illo vel neque sunt, rerum doloremque incidunt laudantium aliquid itaque cum error nobis.</p> </a> </li> <li> <a data-toggle="tab" href="#3"> <h2>Chapter 3</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit.</p> </a> </li> <li> <a data-toggle="tab" href="#4"> <h2>Chapter 4</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit, illo vel neque sunt, rerum doloremque incidunt laudantium aliquid itaque.</p> </a> </li> </ul> </div> </div> </div> </div>
It's because you need to apply the change on the click event. So you may add this code to resize the video each time you click on a chapter (you may add some delay to be sure you get the correct size) :
$('ul.nav-tabs a').click(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); });
You may also use
$(document).ready
function in order to be sure the resize code works well at page load.Full code :
$(document).ready(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); $(window).resize(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }); $('ul.nav-tabs a').click(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); }); });
/* Tools */ .no-padding { padding: 0!important; } .slow-effect { transition: all .2s ease-in-out; -webkit-transition: all .2s ease-in-out; } /* ======================================================================================= */ /* Layout ================================================================================ */ .space { height: 50px; } .container-fluid { padding: 0 4%; } /* Global Styles ========================================================================= */ /* Form Elements */ /*start places*/ body { height: 2000px; } .main-container { border: 2px solid #000; overflow: hidden; } .description { background-color: #898989; padding: 16px 30px; overflow: auto; } .description ul { margin: 0; padding: 0; } .description ul li a { background-color: #898989; color: #fff; padding-bottom: 18px; margin-bottom: 18px; position: relative; border: none; } .nav-tabs>li>a:hover { border: none; border-bottom: 2px solid #fff; background-color: #fff; color: #555555; } .description ul li a>h2 { font-weight: 700; font-size: 35px; margin: 0; } .description ul li a>p { font-size: 18px; line-height: 30px; margin-top: 5px; margin-bottom: 0; } .video-container { position: relative; } .video-container .tools { position: absolute; width: 100%; height: 40px; background-color: #a4a4a4; left: 0; bottom: 0; z-index: 999; } .video-container:hover .tools { visibility: hidden; } #style-1::-webkit-scrollbar { background-color: #898989; } #style-1::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .3); background-color: #adadad } #style-1::-webkit-scrollbar { width: 20px; } @media(min-width: 992px) { .description { border-left: 2px solid #000; } .description ul li a { border-bottom: 2px solid #fff; } } @media(max-width: 991px) { .description { border-left: 2px solid #000; white-space: nowrap; padding: 0; height: auto!important; } .description ul li a { display: inline-block; width: 34%; padding: 14px; text-align: left; overflow: hidden; min-height: 252px; white-space: normal; vertical-align: text-top; margin-bottom: 0; } .description ul li:after { content: ""; display: inline-block; width: 2px; height: 170px; position: absolute; right: 6px; top: 20px; background-color: #fff; } .description ul li:last-child:after { content: ""; display: none; } .description ul li a>h2 { font-size: 22px; } .description ul li a>p { font-size: 14px; line-height: 23px; } } @media screen and (min-width: 220px) and (max-width: 550px) { .description ul li a { padding: 8px; min-height: 200px; } .description ul li a h2 { font-size: 14px; } .description ul li a p { font-size: 10px; line-height: 16px; } }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container-fluid"> <div class="row"> <div class="space"></div> <div id="exTab2" class="col-xs-12 no-padding main-container"> <div class="col-md-9 no-padding video-container tab-content"> <div id="1" class="tabs-container tab-pane fade in active"> <!-- Item-1 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> <source src="test.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> <div id="2" class="tabs-container tab-pane fade"> <!-- Item-2 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="https://www.w3schools.com/html/movie.mp4" type="video/mp4"> <source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> <div id="3" class="tabs-container tab-pane fade"> <!-- Item-3 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> <div id="4" class="tabs-container tab-pane fade"> <!-- Item-4 --> <div class="tools slow-effect"></div><video controls="" width="100%"><source src="test.WEBM" type="video/mp4"> <source src="test.ogg" type="video/ogg"> Your browser does not support HTML5 video.</video> </div> </div> <!-- Item-2 --> <div class="col-md-3 description" id="style-1"> <ul class="nav nav-tabs"> <li class="active"> <a data-toggle="tab" href="#1"> <h2>Chapter 1</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit, illo vel neque sunt doloremque incidunt.</p> </a> </li> <li> <a data-toggle="tab" href="#2"> <h2>Chapter 2</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit, illo vel neque sunt, rerum doloremque incidunt laudantium aliquid itaque cum error nobis.</p> </a> </li> <li> <a data-toggle="tab" href="#3"> <h2>Chapter 3</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit.</p> </a> </li> <li> <a data-toggle="tab" href="#4"> <h2>Chapter 4</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A non velit, illo vel neque sunt, rerum doloremque incidunt laudantium aliquid itaque.</p> </a> </li> </ul> </div> </div> </div> </div>
相关问答
更多jQuery wookmark插件动态div高度(jQuery wookmark plugin dynamic div height)
动态iframe高度与css或jquery(Dynamic iframe height with css or jquery)
jquery动画动态高度div(jquery animating dynamic height div)
动态高度问题(Dynamic height issue)
jQuery将div的高度设置为另一个的“动态高度”(jQuery set height of a div to the 'dynamic height' of another)
Jquery smoothscroll vs动态高度(Jquery smoothscroll vs dynamic height)
动态UITableCellView高度(Dynamic UITableCellView height)
动态容器高度(仅限jQuery)(Dynamic Container Height (jQuery Only))
JQuery动态高度问题(JQuery dynamic height issue)
如何在类中设置动态高度:在使用jquery之前?(how to set dynamic height in class:before using jquery?)
相关文章
更多spring 嵌套事务 的 加锁 问题
怎么递归json嵌套json?
EL 表达式 嵌套问题
ExtJS3.2,在FormPanel中嵌套TabPanel和GridPanel后无法正常显示
谁有sap的相关文档
在线文档显示打印
Solr添加文档到索引
Java 文档注释
Python解析XML文档
微信前景与范围文档
最新问答
更多python的访问器方法有哪些
使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
透明度错误IE11(Transparency bug IE11)
linux的基本操作命令。。。
响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(box-shadow behaviour on elements)
它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640
Copyright ©2023
peixunduo.com All
Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!