使用嵌套子文档的$ 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>
相关问答
更多-
这个插件的作者。 Github存储库包含如何处理这种情况的示例。 保持对应用布局的选择器的引用,然后您可以稍后再次调用wookmark函数来手动更新布局。 检查存储库中“example”文件夹中的“ index.html ”以查看代码。 Author of the plugin here. The Github repository contains an example of how to handle this situation. Keep a reference to the selector th ...
-
在其载荷上更改iframe的高度: $("#the_iframe").load(function() { $(this).height( $(this).contents().find("body").height() ); }); 演示 Change the height of iframe on its load: $("#the_iframe").load(function() { $(this).height( $(this).contents().find("body").height ...
-
为什么不使用完全符合要求的slideUp()和slideDown()方法? 或者更好的是还是自动处理这两种方式的slideToggle() ? $(document).ready(function(e) { // vars var question = $('#faqQues'); var answer = $('#faqAns'); var ansCont = $('#faqAnsCont'); question.click(function() { ...
-
动态高度问题(Dynamic height issue)[2022-01-14]
简单的错误。 您似乎已经忘记在此代码中添加%符号,您还应该将宽度和高度更改为最小宽度和最小高度: .slide { top: 0; opacity: 0; width: 100; height: 100; display: block; position: absolute; transform: scale(1); transition: all .7s ease-in-out; } 所以把它变成这样: .slide { top: 0; opacity: 0; min-width: 100%; mi ... -
jQuery将div的高度设置为另一个的“动态高度”(jQuery set height of a div to the 'dynamic height' of another)[2022-10-21]
这对我来说很好,只是你的类名错误,类名应该是.col-1和.col-2 : $(document).ready(function() { var divHeight = $('.col-1').height(); $('.col-2').css('min-height', divHeight+'px'); }); 这是小提琴 编辑 - 基于评论: 你可以做所有这些,而不使用jQuery Flexbox (在IE 8和9中不支持) - 如果将flex应用到父级div,它将使所有子级高度 ... -
嗡嗡声,我们离开的想法! 如果问题是位置改变,那么将滚动绑定到一个元素而不是固定像素; 让我们说你的菜单中有一个我不知道的按钮,类:'menu-item': 假设 所以: var menuSelector menuSelector = $('.menu-item'); menuSelector.on('click', function(event){ event.preventD ...
-
我下载了你在GitHub上创建的项目并进行了一些更改并使其正常工作。 ViewController中的代码如下所示...... import UIKit class MyTableViewController: UITableViewController { var entries:Array
= [String]() override func viewDidLoad() { super.viewDidLoad() var i = 0 ... -
您可以使用resize事件 ,如下所示:(未经测试) var expandingDiv = $('...'); $(window).resize(function(e) { expandingDiv.height(document.documentElement.clientHeight - (180 + 50)); }); You can use the resize event, like this: (untested) var expandingDiv = $('...'); $(wind ...
-
JQuery动态高度问题(JQuery dynamic height issue)[2020-01-05]
这是因为您需要对click事件应用更改。 因此,您可以添加此代码以在每次单击章节时调整视频大小(您可以添加一些延迟以确保获得正确的大小): $('ul.nav-tabs a').click(function() { setTimeout(function() { var vidHeight = $('.video-container').height(); $('.description').css('height', vidHeight + 'px'); }, 500); }); ... -
我解决了这个问题 设置高度100vh i was solved this problem set height 100vh