mongo DB aggregtion with $cond returning value from field The Next CEO of Stack OverflowUpdate MongoDB field using value of another fieldHow do I drop a MongoDB database from the command line?How to list all collections in the mongo shell?Conditionally evaluate an array element to return$project a new field as the minimum of two fields in mongodbDoes mongodb have a product equivalent of the aggregate $sumFind nested values in mongo 3 with javaMongoDB aggregation pipeline : using $cond to return a $match stage?Need to return cursor and not command_cursor with aggregate()MongoDB: use array returned from aggregation pipeline for $in query in the next stage

Why Were Madagascar and New Zealand Discovered So Late?

What does "Its cash flow is deeply negative" mean?

Increase performance creating Mandelbrot set in python

Why didn't Khan get resurrected in the Genesis Explosion?

How do scammers retract money, while you can’t?

How can I open an app using Terminal?

Should I tutor a student who I know has cheated on their homework?

What size rim is OK?

Removing read access from a file

If I blow insulation everywhere in my attic except the door trap, will heat escape through it?

Solution of this Diophantine Equation

How to write papers efficiently when English isn't my first language?

When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?

Customer Requests (Sometimes) Drive Me Bonkers!

Whats the best way to handle refactoring a big file?

When did Lisp start using symbols for arithmetic?

How to Reset Passwords on Multiple Websites Easily?

Why did we only see the N-1 starfighters in one film?

How to safely derail a train during transit?

Text adventure game code

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?

Are there languages with no euphemisms?

Any way to transfer all permissions from one role to another?



mongo DB aggregtion with $cond returning value from field



The Next CEO of Stack OverflowUpdate MongoDB field using value of another fieldHow do I drop a MongoDB database from the command line?How to list all collections in the mongo shell?Conditionally evaluate an array element to return$project a new field as the minimum of two fields in mongodbDoes mongodb have a product equivalent of the aggregate $sumFind nested values in mongo 3 with javaMongoDB aggregation pipeline : using $cond to return a $match stage?Need to return cursor and not command_cursor with aggregate()MongoDB: use array returned from aggregation pipeline for $in query in the next stage










0















I am trying to have an aggregation that returns a field (in a document) if two conditions are met,
I am doing it at $project stage and tried to write it as follows :



"conversionName" : "$cond" : [ "$and" : [ "$eq" : [ "$webpage", "Product" ] , "$eq" : [ "$isConverted", true ] ] , "$conversion.name", 0 ] 


so if webpage is Product and isConverted is true then it shows the value of the conversion.name at this document.



The current aggregation fails due to : "The $cond accumulator is a unary operator' on server main-shard-00-00-mhxad.gcp.mongodb.net:27017. "


The other parts of the aggregations work perfectly fine.



In what way can I return a value with a $cond commend? If there is non - what another way may address my needs?










share|improve this question




























    0















    I am trying to have an aggregation that returns a field (in a document) if two conditions are met,
    I am doing it at $project stage and tried to write it as follows :



    "conversionName" : "$cond" : [ "$and" : [ "$eq" : [ "$webpage", "Product" ] , "$eq" : [ "$isConverted", true ] ] , "$conversion.name", 0 ] 


    so if webpage is Product and isConverted is true then it shows the value of the conversion.name at this document.



    The current aggregation fails due to : "The $cond accumulator is a unary operator' on server main-shard-00-00-mhxad.gcp.mongodb.net:27017. "


    The other parts of the aggregations work perfectly fine.



    In what way can I return a value with a $cond commend? If there is non - what another way may address my needs?










    share|improve this question


























      0












      0








      0








      I am trying to have an aggregation that returns a field (in a document) if two conditions are met,
      I am doing it at $project stage and tried to write it as follows :



      "conversionName" : "$cond" : [ "$and" : [ "$eq" : [ "$webpage", "Product" ] , "$eq" : [ "$isConverted", true ] ] , "$conversion.name", 0 ] 


      so if webpage is Product and isConverted is true then it shows the value of the conversion.name at this document.



      The current aggregation fails due to : "The $cond accumulator is a unary operator' on server main-shard-00-00-mhxad.gcp.mongodb.net:27017. "


      The other parts of the aggregations work perfectly fine.



      In what way can I return a value with a $cond commend? If there is non - what another way may address my needs?










      share|improve this question
















      I am trying to have an aggregation that returns a field (in a document) if two conditions are met,
      I am doing it at $project stage and tried to write it as follows :



      "conversionName" : "$cond" : [ "$and" : [ "$eq" : [ "$webpage", "Product" ] , "$eq" : [ "$isConverted", true ] ] , "$conversion.name", 0 ] 


      so if webpage is Product and isConverted is true then it shows the value of the conversion.name at this document.



      The current aggregation fails due to : "The $cond accumulator is a unary operator' on server main-shard-00-00-mhxad.gcp.mongodb.net:27017. "


      The other parts of the aggregations work perfectly fine.



      In what way can I return a value with a $cond commend? If there is non - what another way may address my needs?







      mongodb mongodb-query aggregation-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 17:28









      Sagar P. Ghagare

      5472921




      5472921










      asked Mar 21 at 16:29









      Shiri Omer GalShiri Omer Gal

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          In my project, it works perfectly this way :



          $cond: 
          if:
          $and: [
          "$eq" : [ "$webpage", "Product" ] ,
          "$eq" : [ "$isConverted", true ] ,
          ],
          ,
          then: "$conversion.name",
          else: 0,
          ,


          If it does not work (and I dont' see why it won't) then is an expression and can be an other $cond :



          $cond: {
          if: "$eq" : [ "$webpage", "Product" ] ,
          then: $cond: if: "$eq" : [ "$isConverted", true ] , then: "$conversion.name", else: 0,
          else: 0,
          ,





          share|improve this answer























            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%2f55285106%2fmongo-db-aggregtion-with-cond-returning-value-from-field%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









            0














            In my project, it works perfectly this way :



            $cond: 
            if:
            $and: [
            "$eq" : [ "$webpage", "Product" ] ,
            "$eq" : [ "$isConverted", true ] ,
            ],
            ,
            then: "$conversion.name",
            else: 0,
            ,


            If it does not work (and I dont' see why it won't) then is an expression and can be an other $cond :



            $cond: {
            if: "$eq" : [ "$webpage", "Product" ] ,
            then: $cond: if: "$eq" : [ "$isConverted", true ] , then: "$conversion.name", else: 0,
            else: 0,
            ,





            share|improve this answer



























              0














              In my project, it works perfectly this way :



              $cond: 
              if:
              $and: [
              "$eq" : [ "$webpage", "Product" ] ,
              "$eq" : [ "$isConverted", true ] ,
              ],
              ,
              then: "$conversion.name",
              else: 0,
              ,


              If it does not work (and I dont' see why it won't) then is an expression and can be an other $cond :



              $cond: {
              if: "$eq" : [ "$webpage", "Product" ] ,
              then: $cond: if: "$eq" : [ "$isConverted", true ] , then: "$conversion.name", else: 0,
              else: 0,
              ,





              share|improve this answer

























                0












                0








                0







                In my project, it works perfectly this way :



                $cond: 
                if:
                $and: [
                "$eq" : [ "$webpage", "Product" ] ,
                "$eq" : [ "$isConverted", true ] ,
                ],
                ,
                then: "$conversion.name",
                else: 0,
                ,


                If it does not work (and I dont' see why it won't) then is an expression and can be an other $cond :



                $cond: {
                if: "$eq" : [ "$webpage", "Product" ] ,
                then: $cond: if: "$eq" : [ "$isConverted", true ] , then: "$conversion.name", else: 0,
                else: 0,
                ,





                share|improve this answer













                In my project, it works perfectly this way :



                $cond: 
                if:
                $and: [
                "$eq" : [ "$webpage", "Product" ] ,
                "$eq" : [ "$isConverted", true ] ,
                ],
                ,
                then: "$conversion.name",
                else: 0,
                ,


                If it does not work (and I dont' see why it won't) then is an expression and can be an other $cond :



                $cond: {
                if: "$eq" : [ "$webpage", "Product" ] ,
                then: $cond: if: "$eq" : [ "$isConverted", true ] , then: "$conversion.name", else: 0,
                else: 0,
                ,






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 21 at 22:08









                Julien TASSINJulien TASSIN

                2,1781722




                2,1781722





























                    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%2f55285106%2fmongo-db-aggregtion-with-cond-returning-value-from-field%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript