首页 \ 问答 \ 使用嵌套子文档的$ unwind(Using $unwind with nested subdocuments)

使用嵌套子文档的$ 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
更新时间:2024-04-21 13:04

最满意答案

这是因为您需要对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() { ...
  • 简单的错误。 您似乎已经忘记在此代码中添加%符号,您还应该将宽度和高度更改为最小宽度和最小高度: .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 ...
  • 这对我来说很好,只是你的类名错误,类名应该是.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 ...
  • 这是因为您需要对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

相关文章

更多

最新问答

更多
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 高考完可以去做些什么?注意什么?
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 怎么在《我的世界》游戏里面编程
  • .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
  • 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
  • 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
  • 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
  • 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
  • 如何使用变量值创建参数类(How to create a parameter class with variant value)
  • 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
  • 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
  • rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
  • 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
  • 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
  • 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
  • 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
  • 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
  • Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
  • 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
  • 函数调用可以重新排序(Can function calls be reordered)
  • 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
  • 如何解释SBT错误消息(How to interpret SBT error messages)
  • 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)