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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현