Couch DB Mango query to compare 2 fields from the same struct



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have 2 structs with different "_id" values. I want to get only the struct in which the "costCenterFrom" is not equal to "costCenterTo"



 
"_id": "TRAN001",
"_rev": "3-945670849a142da8d57a79f7c13040dd",
"actionCode": "Transfer",
"bankID": "1000003",
"costCenterFrom": "30000004",
"costCenterTo": "30000005",
"effectiveDateOfAction": "30-08-2018",
"employeeName": "Kumar,Vinoth",
"transferReportID": "TRAN001",
"~version": "22:0"



"_id": "TRAN002",
"_rev": "2-1983dcdedc144d75b14c1ef73771fc42",
"actionCode": "Transfer",
"bankID": "1000004",
"costCenterFrom": "30000002",
"costCenterTo": "30000002",
"effectiveDateOfAction": "31-08-2018",
"employeeName": "Kumar",
"transferReportID": "TRAN002",
"~version": "12:0"



Please find the query i tried



 queryStringTrans := fmt.Sprintf(""selector":"transferReportID": 
"$ne":"%s"", "null")
queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans)


The above query (queryResultsTrans) will give all the record that has "transferReportID" field.



var costcenterFrom string
var costcenterTo string

var resultsdummy KeyRecordTransfer
err = json.Unmarshal(byte(queryResultsTrans), &resultsdummy)

for _, trasnresult := range resultsdummy
fmt.Println(" resultsdummy Record : ", trasnresult)
costcenterFrom = trasnresult.Record.CostCenterFrom
costcenterTo = trasnresult.Record.CostCenterTo

if (costcenterFrom != costcenterTo)
fmt.Println("costcenterFrom && costCenterTo : ", costcenterFrom,
costcenterTo)

//var costcenterFrom = resultsdummy[0].Record.CostCenterFrom
//var costcenterTo = resultsdummy[0].Record.CostCenterTo


//query to get the Transfer Reports


The below query which i tried to compare the "costCenterFrom" and "costCenterTo" fields



queryString := fmt.Sprintf(""selector":"$and":["transferReportID": 
"$ne":"%s","%s":"$ne":"%s","effectiveDateOfAction":
"$gt":"%s"]","null",costcenterFrom,costcenterTo,"30-07-2018")
queryResults, err := getQueryResultForQueryString(stub, queryString)


Im not getting the expected result. Could you please help me in getting the query to compare the fields inside the same struct?



My raw query:



 
"selector":
"$and": [

"transferReportID":
"$ne": null

,

"costcenterFrom":
"$ne": "costcenterTo"

,

"effectiveDateOfAction":
"$gt": "30-07-2018"


]











share|improve this question
























  • Have you tried your request manually with Fauxton? This could help debugging your code.

    – Alexis Côté
    Nov 15 '18 at 16:06











  • @AlexisCôté I have tried. But I didnt get the output. Could you please help me?

    – sasi
    Nov 15 '18 at 16:48











  • Can you give us the raw query that you attempted. It would be easier that trying to read your code

    – Alexis Côté
    Nov 15 '18 at 21:33











  • @AlexisCôté I have updated my code with raw query. Could you please check that?

    – sasi
    Nov 20 '18 at 5:45

















0















I have 2 structs with different "_id" values. I want to get only the struct in which the "costCenterFrom" is not equal to "costCenterTo"



 
"_id": "TRAN001",
"_rev": "3-945670849a142da8d57a79f7c13040dd",
"actionCode": "Transfer",
"bankID": "1000003",
"costCenterFrom": "30000004",
"costCenterTo": "30000005",
"effectiveDateOfAction": "30-08-2018",
"employeeName": "Kumar,Vinoth",
"transferReportID": "TRAN001",
"~version": "22:0"



"_id": "TRAN002",
"_rev": "2-1983dcdedc144d75b14c1ef73771fc42",
"actionCode": "Transfer",
"bankID": "1000004",
"costCenterFrom": "30000002",
"costCenterTo": "30000002",
"effectiveDateOfAction": "31-08-2018",
"employeeName": "Kumar",
"transferReportID": "TRAN002",
"~version": "12:0"



Please find the query i tried



 queryStringTrans := fmt.Sprintf(""selector":"transferReportID": 
"$ne":"%s"", "null")
queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans)


The above query (queryResultsTrans) will give all the record that has "transferReportID" field.



var costcenterFrom string
var costcenterTo string

var resultsdummy KeyRecordTransfer
err = json.Unmarshal(byte(queryResultsTrans), &resultsdummy)

for _, trasnresult := range resultsdummy
fmt.Println(" resultsdummy Record : ", trasnresult)
costcenterFrom = trasnresult.Record.CostCenterFrom
costcenterTo = trasnresult.Record.CostCenterTo

if (costcenterFrom != costcenterTo)
fmt.Println("costcenterFrom && costCenterTo : ", costcenterFrom,
costcenterTo)

//var costcenterFrom = resultsdummy[0].Record.CostCenterFrom
//var costcenterTo = resultsdummy[0].Record.CostCenterTo


//query to get the Transfer Reports


The below query which i tried to compare the "costCenterFrom" and "costCenterTo" fields



queryString := fmt.Sprintf(""selector":"$and":["transferReportID": 
"$ne":"%s","%s":"$ne":"%s","effectiveDateOfAction":
"$gt":"%s"]","null",costcenterFrom,costcenterTo,"30-07-2018")
queryResults, err := getQueryResultForQueryString(stub, queryString)


Im not getting the expected result. Could you please help me in getting the query to compare the fields inside the same struct?



My raw query:



 
"selector":
"$and": [

"transferReportID":
"$ne": null

,

"costcenterFrom":
"$ne": "costcenterTo"

,

"effectiveDateOfAction":
"$gt": "30-07-2018"


]











share|improve this question
























  • Have you tried your request manually with Fauxton? This could help debugging your code.

    – Alexis Côté
    Nov 15 '18 at 16:06











  • @AlexisCôté I have tried. But I didnt get the output. Could you please help me?

    – sasi
    Nov 15 '18 at 16:48











  • Can you give us the raw query that you attempted. It would be easier that trying to read your code

    – Alexis Côté
    Nov 15 '18 at 21:33











  • @AlexisCôté I have updated my code with raw query. Could you please check that?

    – sasi
    Nov 20 '18 at 5:45













0












0








0








I have 2 structs with different "_id" values. I want to get only the struct in which the "costCenterFrom" is not equal to "costCenterTo"



 
"_id": "TRAN001",
"_rev": "3-945670849a142da8d57a79f7c13040dd",
"actionCode": "Transfer",
"bankID": "1000003",
"costCenterFrom": "30000004",
"costCenterTo": "30000005",
"effectiveDateOfAction": "30-08-2018",
"employeeName": "Kumar,Vinoth",
"transferReportID": "TRAN001",
"~version": "22:0"



"_id": "TRAN002",
"_rev": "2-1983dcdedc144d75b14c1ef73771fc42",
"actionCode": "Transfer",
"bankID": "1000004",
"costCenterFrom": "30000002",
"costCenterTo": "30000002",
"effectiveDateOfAction": "31-08-2018",
"employeeName": "Kumar",
"transferReportID": "TRAN002",
"~version": "12:0"



Please find the query i tried



 queryStringTrans := fmt.Sprintf(""selector":"transferReportID": 
"$ne":"%s"", "null")
queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans)


The above query (queryResultsTrans) will give all the record that has "transferReportID" field.



var costcenterFrom string
var costcenterTo string

var resultsdummy KeyRecordTransfer
err = json.Unmarshal(byte(queryResultsTrans), &resultsdummy)

for _, trasnresult := range resultsdummy
fmt.Println(" resultsdummy Record : ", trasnresult)
costcenterFrom = trasnresult.Record.CostCenterFrom
costcenterTo = trasnresult.Record.CostCenterTo

if (costcenterFrom != costcenterTo)
fmt.Println("costcenterFrom && costCenterTo : ", costcenterFrom,
costcenterTo)

//var costcenterFrom = resultsdummy[0].Record.CostCenterFrom
//var costcenterTo = resultsdummy[0].Record.CostCenterTo


//query to get the Transfer Reports


The below query which i tried to compare the "costCenterFrom" and "costCenterTo" fields



queryString := fmt.Sprintf(""selector":"$and":["transferReportID": 
"$ne":"%s","%s":"$ne":"%s","effectiveDateOfAction":
"$gt":"%s"]","null",costcenterFrom,costcenterTo,"30-07-2018")
queryResults, err := getQueryResultForQueryString(stub, queryString)


Im not getting the expected result. Could you please help me in getting the query to compare the fields inside the same struct?



My raw query:



 
"selector":
"$and": [

"transferReportID":
"$ne": null

,

"costcenterFrom":
"$ne": "costcenterTo"

,

"effectiveDateOfAction":
"$gt": "30-07-2018"


]











share|improve this question
















I have 2 structs with different "_id" values. I want to get only the struct in which the "costCenterFrom" is not equal to "costCenterTo"



 
"_id": "TRAN001",
"_rev": "3-945670849a142da8d57a79f7c13040dd",
"actionCode": "Transfer",
"bankID": "1000003",
"costCenterFrom": "30000004",
"costCenterTo": "30000005",
"effectiveDateOfAction": "30-08-2018",
"employeeName": "Kumar,Vinoth",
"transferReportID": "TRAN001",
"~version": "22:0"



"_id": "TRAN002",
"_rev": "2-1983dcdedc144d75b14c1ef73771fc42",
"actionCode": "Transfer",
"bankID": "1000004",
"costCenterFrom": "30000002",
"costCenterTo": "30000002",
"effectiveDateOfAction": "31-08-2018",
"employeeName": "Kumar",
"transferReportID": "TRAN002",
"~version": "12:0"



Please find the query i tried



 queryStringTrans := fmt.Sprintf(""selector":"transferReportID": 
"$ne":"%s"", "null")
queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans)


The above query (queryResultsTrans) will give all the record that has "transferReportID" field.



var costcenterFrom string
var costcenterTo string

var resultsdummy KeyRecordTransfer
err = json.Unmarshal(byte(queryResultsTrans), &resultsdummy)

for _, trasnresult := range resultsdummy
fmt.Println(" resultsdummy Record : ", trasnresult)
costcenterFrom = trasnresult.Record.CostCenterFrom
costcenterTo = trasnresult.Record.CostCenterTo

if (costcenterFrom != costcenterTo)
fmt.Println("costcenterFrom && costCenterTo : ", costcenterFrom,
costcenterTo)

//var costcenterFrom = resultsdummy[0].Record.CostCenterFrom
//var costcenterTo = resultsdummy[0].Record.CostCenterTo


//query to get the Transfer Reports


The below query which i tried to compare the "costCenterFrom" and "costCenterTo" fields



queryString := fmt.Sprintf(""selector":"$and":["transferReportID": 
"$ne":"%s","%s":"$ne":"%s","effectiveDateOfAction":
"$gt":"%s"]","null",costcenterFrom,costcenterTo,"30-07-2018")
queryResults, err := getQueryResultForQueryString(stub, queryString)


Im not getting the expected result. Could you please help me in getting the query to compare the fields inside the same struct?



My raw query:



 
"selector":
"$and": [

"transferReportID":
"$ne": null

,

"costcenterFrom":
"$ne": "costcenterTo"

,

"effectiveDateOfAction":
"$gt": "30-07-2018"


]








couchdb hyperledger-fabric mangodb couchdb-mango






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 5:45







sasi

















asked Nov 15 '18 at 8:08









sasisasi

861312




861312












  • Have you tried your request manually with Fauxton? This could help debugging your code.

    – Alexis Côté
    Nov 15 '18 at 16:06











  • @AlexisCôté I have tried. But I didnt get the output. Could you please help me?

    – sasi
    Nov 15 '18 at 16:48











  • Can you give us the raw query that you attempted. It would be easier that trying to read your code

    – Alexis Côté
    Nov 15 '18 at 21:33











  • @AlexisCôté I have updated my code with raw query. Could you please check that?

    – sasi
    Nov 20 '18 at 5:45

















  • Have you tried your request manually with Fauxton? This could help debugging your code.

    – Alexis Côté
    Nov 15 '18 at 16:06











  • @AlexisCôté I have tried. But I didnt get the output. Could you please help me?

    – sasi
    Nov 15 '18 at 16:48











  • Can you give us the raw query that you attempted. It would be easier that trying to read your code

    – Alexis Côté
    Nov 15 '18 at 21:33











  • @AlexisCôté I have updated my code with raw query. Could you please check that?

    – sasi
    Nov 20 '18 at 5:45
















Have you tried your request manually with Fauxton? This could help debugging your code.

– Alexis Côté
Nov 15 '18 at 16:06





Have you tried your request manually with Fauxton? This could help debugging your code.

– Alexis Côté
Nov 15 '18 at 16:06













@AlexisCôté I have tried. But I didnt get the output. Could you please help me?

– sasi
Nov 15 '18 at 16:48





@AlexisCôté I have tried. But I didnt get the output. Could you please help me?

– sasi
Nov 15 '18 at 16:48













Can you give us the raw query that you attempted. It would be easier that trying to read your code

– Alexis Côté
Nov 15 '18 at 21:33





Can you give us the raw query that you attempted. It would be easier that trying to read your code

– Alexis Côté
Nov 15 '18 at 21:33













@AlexisCôté I have updated my code with raw query. Could you please check that?

– sasi
Nov 20 '18 at 5:45





@AlexisCôté I have updated my code with raw query. Could you please check that?

– sasi
Nov 20 '18 at 5:45












1 Answer
1






active

oldest

votes


















1














I tried your query and you have some typos.



So in your query, you have a missing camel case: costcenterFrom
From my tests, the $ne seems to check if the field exist.



Other comment, you can't compare other object fields. I see that you're trying to compare the costCenterTo property with the costCenterFrom but that's not supported by mango at the moment.






share|improve this answer























  • Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

    – sasi
    Nov 22 '18 at 14:14






  • 1





    CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

    – Alexis Côté
    Nov 22 '18 at 14:44











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%2f53314907%2fcouch-db-mango-query-to-compare-2-fields-from-the-same-struct%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














I tried your query and you have some typos.



So in your query, you have a missing camel case: costcenterFrom
From my tests, the $ne seems to check if the field exist.



Other comment, you can't compare other object fields. I see that you're trying to compare the costCenterTo property with the costCenterFrom but that's not supported by mango at the moment.






share|improve this answer























  • Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

    – sasi
    Nov 22 '18 at 14:14






  • 1





    CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

    – Alexis Côté
    Nov 22 '18 at 14:44















1














I tried your query and you have some typos.



So in your query, you have a missing camel case: costcenterFrom
From my tests, the $ne seems to check if the field exist.



Other comment, you can't compare other object fields. I see that you're trying to compare the costCenterTo property with the costCenterFrom but that's not supported by mango at the moment.






share|improve this answer























  • Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

    – sasi
    Nov 22 '18 at 14:14






  • 1





    CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

    – Alexis Côté
    Nov 22 '18 at 14:44













1












1








1







I tried your query and you have some typos.



So in your query, you have a missing camel case: costcenterFrom
From my tests, the $ne seems to check if the field exist.



Other comment, you can't compare other object fields. I see that you're trying to compare the costCenterTo property with the costCenterFrom but that's not supported by mango at the moment.






share|improve this answer













I tried your query and you have some typos.



So in your query, you have a missing camel case: costcenterFrom
From my tests, the $ne seems to check if the field exist.



Other comment, you can't compare other object fields. I see that you're trying to compare the costCenterTo property with the costCenterFrom but that's not supported by mango at the moment.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 16:18









Alexis CôtéAlexis Côté

2,9402824




2,9402824












  • Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

    – sasi
    Nov 22 '18 at 14:14






  • 1





    CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

    – Alexis Côté
    Nov 22 '18 at 14:44

















  • Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

    – sasi
    Nov 22 '18 at 14:14






  • 1





    CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

    – Alexis Côté
    Nov 22 '18 at 14:44
















Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

– sasi
Nov 22 '18 at 14:14





Thank you for your response. It could be very much useful for me, if you could suggest any other way to crack this?

– sasi
Nov 22 '18 at 14:14




1




1





CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

– Alexis Côté
Nov 22 '18 at 14:44





CouchDB is not really designed to do that kind of stuff. You might want to reach CouchDB's slack to have the feedback from people who develops CouchDB

– Alexis Côté
Nov 22 '18 at 14:44



















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%2f53314907%2fcouch-db-mango-query-to-compare-2-fields-from-the-same-struct%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo