您可以使用 MongoDB 的 $in 运算符。官方文档链接:Click
示例:
我在 queryAns 集合中有两个文档
db.queryAns.find({}).pretty()
{
"_id" : ObjectId("5b98e5d17d542a2560ec026d"),
"RequestID" : "1536746958",
"JSON_Request" : [
2,
"1536746958",
"Heartbeat1",
{
}
],
"JSON_Response" : [
3,
"1536746958",
{
"currentTime" : "2018-09-12T10:09:21.435Z"
}
]
}
{
"_id" : ObjectId("5b98e5d17d542a2560ec024d"),
"RequestID" : "1536746958",
"JSON_Request" : [
2,
"1536746958",
"Heartbeat",
{
}
],
"JSON_Response" : [
3,
"1536746958",
{
"currentTime" : "2018-09-12T10:09:21.435Z"
}
]
}
并且只过滤掉“JSON_Request”中包含“Heartbeat”的结果,
db.queryAns.find({"JSON_Request": {$in: ["心跳"]}}).pretty()
{
"_id" : ObjectId("5b98e5d17d542a2560ec024d"),
"RequestID" : "1536746958",
"JSON_Request" : [
2,
"1536746958",
"Heartbeat",
{
}
],
"JSON_Response" : [
3,
"1536746958",
{
"currentTime" : "2018-09-12T10:09:21.435Z"
}
]
}