【发布时间】:2019-02-28 22:12:17
【问题描述】:
I have to find "exitState" : this is single document , if multiple documents how to find.
{
“_id”:“abc”,
"exitType" : "挂起",
“exitState”:“印度”,
“结果”:“成功”,
“CEV”:[
{
"LogID" : "CEV",
“报告模式”:“N”,
"Log_DateTime" : "02:23:2016 00:17:48:913",
"Log_TS" : NumberLong(1456186668913),
“服务类型”:“电话”,
"MsgID" : "25000",
“系统名称”:“test123”,
“进程ID”:“9611”,
“端口”:“0”,
"ModuleName" : "ArcCDR::CDR_CustomEvent",
"AppName" : "testVXML2",
"MsgTxt" : "abc::24::Test::outcome=Successful$$$exitType=Hang$$$exitState=INDIA",
"Record_Key" : "abc",
“令牌1”:“24”,
“客户名称”:“测试”,
"CEV_MsgTxt" : "结果=成功$$$exitType=Hang$$$exitState=INDIA",
“结果”:“成功”,
"exitType" : "挂起",
“exitState”:“印度”
}
],
“英语语言”,
"SC_TS" : ISODate("2016-02-23T00:17:06.060+0000"),
"SC_TimeMS" : NumberLong(1456186626060),
“CDR_SC”:{
"LogID" : "CDR",
“报告模式”:“N”,
"Log_DateTime" : "02:23:2016 00:17:06:060",
"Log_TS" : NumberLong(1456186626060),
“服务类型”:“电话”,
"MsgID" : "20010",
“系统名称”:“test123”,
“进程ID”:“9611”,
“端口”:“0”,
"ModuleName" : "TEL_AnswerCall",
"AppName" : "testVXML2",
"MsgTxt" : "abc:SC:testVXML2:452:607856:0223201600170606::",
"Record_Key" : "abc",
“CDR_Type”:“SC”,
"Token2" : "testVXML2",
“令牌3”:“452”,
“令牌4”:“607856”,
“令牌5”:“0223201600170606”
},
" SC_TS_TZ" : ISODate("2016-02-23T00:17:06.060+0000"),
"EC_TS" : ISODate("2016-02-23T00:17:48.910+0000"),
"EC_TS_TZ" : ISODate("2016-02-23T00:17:48.910+0000"),
“EC_TimeMS”:NumberLong(1456186668910),
“CDR_EC”:{
"LogID" : "CDR",
“报告模式”:“N”,
"Log_DateTime" : "02:23:2016 00:17:48:910",
"Log_TS" : NumberLong(1456186668910),
“服务类型”:“电话”,
"MsgID" : "20011",
“系统名称”:“test123”,
“进程ID”:“9611”,
“端口”:“0”,
“模块名称”:“TEL_SRRecognizeV2”,
"AppName" : "testVXML2",
"MsgTxt" : "abc:EC:02:0223201600174891::",
"Record_Key" : "abc",
“CDR_Type”:“EC”,
“令牌2”:“02”,
“令牌3”:“0223201600174891”
},
“客户名称”:“测试”
}
以下是我的查询,但无法在所有文档中找到 exitState。可以吗?
dbo.ProductModel.aggregate([ {$match: {"EC_TS":{$gte:new Date(start.toISOString()), $lte:new Date(end.toISOString())}} }, {$组: {_id: '$exitState', count : {$sum: 1} } } ]).toArray(function(err, result4) { console.log(+ result4[0]["exitState"]); console.log("总退出状态=" + result4[0]["total"]); q4result=(result4[0]["total"]); }); });【问题讨论】:
-
使用
$exists运算符。 -
能否请您在此处 ping 查询..
-
dbo.ProductModel.find({"EC_TS":{$gte:new Date(start.toISOString()), $lte:new Date(end.toISOString())}, exitState: { "$exists": true }}) -
还是一样没有找到超过元素
-
然后去掉
$lte$gte在所有文档中查找?dbo.ProductModel.find({ exitState: { "$exists": true }})
标签: node.js mongodb mongodb-query