Couchdb Coach DB Mango查询比较同一结构中的两个字段
我有两个具有不同“\u id”值的结构。我只想获取其中“costCenterFrom”不等于“costCenterTo”的结构 请查找我尝试的查询Couchdb Coach DB Mango查询比较同一结构中的两个字段,couchdb,hyperledger-fabric,mangodb,couchdb-mango,Couchdb,Hyperledger Fabric,Mangodb,Couchdb Mango,我有两个具有不同“\u id”值的结构。我只想获取其中“costCenterFrom”不等于“costCenterTo”的结构 请查找我尝试的查询 queryStringTrans := fmt.Sprintf("{\"selector\":{\"transferReportID\": {\"$ne\":\"%s\"}}}", "null") queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans := fmt.Sprintf("{\"selector\":{\"transferReportID\":
{\"$ne\":\"%s\"}}}", "null")
queryResultsTrans, err := getQueryResultForQueryString(stub,
queryStringTrans)
上述查询(queryResultsTrans)将给出所有具有“transferReportID”字段的记录
下面是我试图比较“costCenterFrom”和“costCenterTo”字段的查询
我没有得到预期的结果。你能帮我把同一个结构中的字段进行比较吗
我的原始查询:
{
"selector": {
"$and": [
{
"transferReportID": {
"$ne": null
}
},
{
"costcenterFrom": {
"$ne": "costcenterTo"
}
},
{
"effectiveDateOfAction": {
"$gt": "30-07-2018"
}
}
]
}
}
我试过你的问题,你有一些打字错误 因此,在您的查询中,缺少了一个驼峰大小写:cost
c
enterFrom
根据我的测试,$ne似乎检查字段是否存在
其他注释,无法比较其他对象字段。我看到您试图将
costCenterTo
属性与costCenterFrom
进行比较,但mango目前不支持这一点。您是否与Fauxton手动尝试过您的请求?这可能有助于调试您的代码。@AlexisCôté我已经试过了。但是我没有得到输出。你能帮我吗?你能告诉我们你尝试的原始查询吗。试着读懂你的文章会更容易code@AlexisCôté我已经用原始查询更新了代码。你能检查一下吗?谢谢你的回复。如果你能建议其他方法来破解这个问题的话,这对我来说可能非常有用。CouchDB并不是专门设计来做这种事情的。您可能希望访问CouchDB的slack,以获得开发CouchDB的人员的反馈
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
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"
}
}
]
}
}