Mongo aggregate remove group if condition in sub array2019 Community Moderator ElectionMongoDB group aggregation of multiple elements and sub-documentsMongo average aggregation query with no groupMongo Aggregation select and push last element in arrayMongo aggregate group by one array elementdefine $group as a list in mongo aggregate queryMongo aggregate group by multiple valuesmongodb aggregation $group and then $push a objectOutput from aggregate array of objects to document keysMongoDB aggregate pipeline groupmongodb aggregation with multiple sub groups

ERC721: How to get the owned tokens of an address

Converting a variable frequency to TTL HIGH and LOW levels, based on a fixed (possible non-fixed?) frequency

Describing a chess game in a novel

Is it normal that my co-workers at a fitness company criticize my food choices?

What is "focus distance lower/upper" and how is it different from depth of field?

How do I change two letters closest to a string and one letter immediately after a string using Notepad++?

What is the Japanese sound word for the clinking of money?

Why does a Star of David appear at a rally with Francisco Franco?

Is there a place to find the pricing for things not mentioned in the PHB? (non-magical)

Is "upgrade" the right word to use in this context?

Why do tuner card drivers fail to build after kernel update to 4.4.0-143-generic?

What did “the good wine” (τὸν καλὸν οἶνον) mean in John 2:10?

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Math equation in non italic font

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Are Roman Catholic priests ever addressed as pastor

Problem with FindRoot

How do I hide Chekhov's Gun?

Shortcut for setting origin to vertex

As a new Ubuntu desktop 18.04 LTS user, do I need to use ufw for a firewall or is iptables sufficient?

Are all passive ability checks floors for active ability checks?

I got the following comment from a reputed math journal. What does it mean?

Planetary tidal locking causing asymetrical water distribution

Why no Iridium-level flares from other satellites?



Mongo aggregate remove group if condition in sub array



2019 Community Moderator ElectionMongoDB group aggregation of multiple elements and sub-documentsMongo average aggregation query with no groupMongo Aggregation select and push last element in arrayMongo aggregate group by one array elementdefine $group as a list in mongo aggregate queryMongo aggregate group by multiple valuesmongodb aggregation $group and then $push a objectOutput from aggregate array of objects to document keysMongoDB aggregate pipeline groupmongodb aggregation with multiple sub groups










0















At a certain point of my pipeline, I have a structure like this :



[

_id: 1,
elems1: [sub : date: xxx, sub: date: yyy],
elems2: [sub: date: zzz, sub: date: qqq]
,
...
]


Which comes from a grouping :



$group: 
_id: '$user.id',
elems1:
$push: sub: '$other'
,
elems2:
$push: sub: '$other'


}


Now I want to delete the groups that have an element in elems1 OR elems2 with sub.date less than a certain date, how could I do this ?










share|improve this question




























    0















    At a certain point of my pipeline, I have a structure like this :



    [

    _id: 1,
    elems1: [sub : date: xxx, sub: date: yyy],
    elems2: [sub: date: zzz, sub: date: qqq]
    ,
    ...
    ]


    Which comes from a grouping :



    $group: 
    _id: '$user.id',
    elems1:
    $push: sub: '$other'
    ,
    elems2:
    $push: sub: '$other'


    }


    Now I want to delete the groups that have an element in elems1 OR elems2 with sub.date less than a certain date, how could I do this ?










    share|improve this question


























      0












      0








      0








      At a certain point of my pipeline, I have a structure like this :



      [

      _id: 1,
      elems1: [sub : date: xxx, sub: date: yyy],
      elems2: [sub: date: zzz, sub: date: qqq]
      ,
      ...
      ]


      Which comes from a grouping :



      $group: 
      _id: '$user.id',
      elems1:
      $push: sub: '$other'
      ,
      elems2:
      $push: sub: '$other'


      }


      Now I want to delete the groups that have an element in elems1 OR elems2 with sub.date less than a certain date, how could I do this ?










      share|improve this question
















      At a certain point of my pipeline, I have a structure like this :



      [

      _id: 1,
      elems1: [sub : date: xxx, sub: date: yyy],
      elems2: [sub: date: zzz, sub: date: qqq]
      ,
      ...
      ]


      Which comes from a grouping :



      $group: 
      _id: '$user.id',
      elems1:
      $push: sub: '$other'
      ,
      elems2:
      $push: sub: '$other'


      }


      Now I want to delete the groups that have an element in elems1 OR elems2 with sub.date less than a certain date, how could I do this ?







      mongodb aggregation-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 16:13







      HRK44

















      asked Mar 7 at 15:18









      HRK44HRK44

      473215




      473215






















          1 Answer
          1






          active

          oldest

          votes


















          1














          When you do your $group, you can also track the "minElemDate" and then $match by that in the next pipeline stage.



          $group: 
          _id: "$user.id",
          elem1s: ...,
          elem2s: ...
          minElemDate:
          $min:
          $cond: [
          $or: [condition1, condition2] ,
          "$user.date",
          null
          ]


          ,
          $match: $gte: ["$minElemDate", minDate]





          share|improve this answer

























          • I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

            – HRK44
            Mar 8 at 12:55











          • $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

            – willis
            Mar 8 at 16:10












          • I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

            – HRK44
            Mar 8 at 16:13











          • tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

            – willis
            Mar 8 at 16:16











          • The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

            – HRK44
            Mar 8 at 16:17










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047190%2fmongo-aggregate-remove-group-if-condition-in-sub-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          When you do your $group, you can also track the "minElemDate" and then $match by that in the next pipeline stage.



          $group: 
          _id: "$user.id",
          elem1s: ...,
          elem2s: ...
          minElemDate:
          $min:
          $cond: [
          $or: [condition1, condition2] ,
          "$user.date",
          null
          ]


          ,
          $match: $gte: ["$minElemDate", minDate]





          share|improve this answer

























          • I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

            – HRK44
            Mar 8 at 12:55











          • $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

            – willis
            Mar 8 at 16:10












          • I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

            – HRK44
            Mar 8 at 16:13











          • tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

            – willis
            Mar 8 at 16:16











          • The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

            – HRK44
            Mar 8 at 16:17















          1














          When you do your $group, you can also track the "minElemDate" and then $match by that in the next pipeline stage.



          $group: 
          _id: "$user.id",
          elem1s: ...,
          elem2s: ...
          minElemDate:
          $min:
          $cond: [
          $or: [condition1, condition2] ,
          "$user.date",
          null
          ]


          ,
          $match: $gte: ["$minElemDate", minDate]





          share|improve this answer

























          • I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

            – HRK44
            Mar 8 at 12:55











          • $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

            – willis
            Mar 8 at 16:10












          • I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

            – HRK44
            Mar 8 at 16:13











          • tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

            – willis
            Mar 8 at 16:16











          • The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

            – HRK44
            Mar 8 at 16:17













          1












          1








          1







          When you do your $group, you can also track the "minElemDate" and then $match by that in the next pipeline stage.



          $group: 
          _id: "$user.id",
          elem1s: ...,
          elem2s: ...
          minElemDate:
          $min:
          $cond: [
          $or: [condition1, condition2] ,
          "$user.date",
          null
          ]


          ,
          $match: $gte: ["$minElemDate", minDate]





          share|improve this answer















          When you do your $group, you can also track the "minElemDate" and then $match by that in the next pipeline stage.



          $group: 
          _id: "$user.id",
          elem1s: ...,
          elem2s: ...
          minElemDate:
          $min:
          $cond: [
          $or: [condition1, condition2] ,
          "$user.date",
          null
          ]


          ,
          $match: $gte: ["$minElemDate", minDate]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 16:11

























          answered Mar 7 at 20:10









          williswillis

          79429




          79429












          • I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

            – HRK44
            Mar 8 at 12:55











          • $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

            – willis
            Mar 8 at 16:10












          • I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

            – HRK44
            Mar 8 at 16:13











          • tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

            – willis
            Mar 8 at 16:16











          • The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

            – HRK44
            Mar 8 at 16:17

















          • I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

            – HRK44
            Mar 8 at 12:55











          • $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

            – willis
            Mar 8 at 16:10












          • I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

            – HRK44
            Mar 8 at 16:13











          • tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

            – willis
            Mar 8 at 16:16











          • The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

            – HRK44
            Mar 8 at 16:17
















          I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

          – HRK44
          Mar 8 at 12:55





          I like this idea, can you please elaborate on what to put in condition1 and condition2 ? That's the part where I'm confused

          – HRK44
          Mar 8 at 12:55













          $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

          – willis
          Mar 8 at 16:10






          $eq: ['$user.name', 'L'] and $eq: ['$user.name', 'L'] -- it seems like those are the elements that you care about

          – willis
          Mar 8 at 16:10














          I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

          – HRK44
          Mar 8 at 16:13





          I will remove this part, maybe it is making it confusing. I care only about the date... I will update my question

          – HRK44
          Mar 8 at 16:13













          tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

          – willis
          Mar 8 at 16:16





          tldr of my answer -- when you do the group, also track the min date. don't try and filter it out afterwards because it'll be harder

          – willis
          Mar 8 at 16:16













          The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

          – HRK44
          Mar 8 at 16:17





          The problem is that I don't know what to put in the $min block, since I want the min of the object date inside the array

          – HRK44
          Mar 8 at 16:17



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047190%2fmongo-aggregate-remove-group-if-condition-in-sub-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229