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
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
add a comment |
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
add a comment |
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
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
mongodb mongodb-query aggregation-framework
edited Mar 21 at 17:28
Sagar P. Ghagare
5472921
5472921
asked Mar 21 at 16:29
Shiri Omer GalShiri Omer Gal
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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,
,
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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,
,
add a comment |
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,
,
add a comment |
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,
,
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,
,
answered Mar 21 at 22:08
Julien TASSINJulien TASSIN
2,1781722
2,1781722
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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