我有两个具有不同“_id”值的结构体。我只想获取其中“costCenterFrom”不等于“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"
}
请查找我尝试的查询
queryStringTrans := fmt.Sprintf("{\"selector\":{\"transferReportID\":
{\"$ne\":\"%s\"}}}", "null")
queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans)
上面的查询(queryResultsTrans)将给予所有具有“transferReportID”字段的记录。
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
下面是我试图比较“costCenterFrom”和“costCenterTo”字段的查询
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)
我没有得到预期的结果。您能帮助我获得查询以比较同一结构中的字段吗?
我的原始查询:
{
"selector": {
"$and": [
{
"transferReportID": {
"$ne": null
}
},
{
"costcenterFrom": {
"$ne": "costcenterTo"
}
},
{
"effectiveDateOfAction": {
"$gt": "30-07-2018"
}
}
]
}
}
1条答案
按热度按时间qgelzfjb1#
我试过你的查询,你有一些错别字。
因此,在您的查询中,您有一个缺失的camel案例:cost
c
enterFrom从我的测试来看,$ne似乎在检查字段是否存在。其他注解,你不能比较其他对象字段。我看到你试图比较
costCenterTo
属性和costCenterFrom
属性,但芒果目前不支持。