我有一个mongodb查询,我想找到完全匹配的词“已批准" [英] I have a mongodb query and I want to find the exact match word “Approved”
本文介绍了我有一个mongodb查询,我想找到完全匹配的词“已批准"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个mongodb查询,我想在名为"Sales.Action"的数组中找到完全匹配的词已批准".
I have a mongodb query and I want to find the exact match word "Approved" in Array named "Sales.Action".
但是另一个"Sales.Action"数组具有值"Approve",该值也将返回.
But the other "Sales.Action" array has the value "Approve" which is also returning.
我尝试了$ elemMatch,但仍然无法正常工作.
I have tried $elemMatch but still it is not working.
这是我的json:
{
"Sales" : [
{
"Action" : [
"Approved"
],
"Log" : [
"Created on: 04/20/2020 42:04:04"
]
},
{
"Action" : [
"Approve",
"Decline",
"Edit",
"Remarks"
],
"Log" : [
"Created on: 04/20/2020 42:04:04"
]
},
{
"Action" : [
"Approve",
"Decline",
"Edit",
"Remarks"
],
"Log" : [
"Created on: 04/21/2020 412:04:04"
]
},
{
"Action" : [
"Approve",
"Decline",
"Edit",
"Remarks"
],
"Log" : [
"Created on: 04/21/2020 412:04:04"
]
},
{
"Action" : [
"Approve",
"Decline",
"Edit",
"Remarks"
],
"Log" : [
"Created on: 04/23/2020 44:04:04"
]
}
]
}
但是我只需要一个就可以退回.
But I need only one to return.
推荐答案
尝试此代码,我认为这对您有用
try this code i think this works for you
db.getCollection('your_collection').aggregate([
{ $unwind: '$Sales' },
{
$match: {'Sales.Action': 'Approve' }
},
])
这篇关于我有一个mongodb查询,我想找到完全匹配的词“已批准"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文