仅在子记录密钥中搜索php mongo搜索
想在mongo中获取行。
我想匹配php mongo中的子登记件,
我 在Mongo中,
"invoice_id":0,"users":{"14":"2022-06-09 10:56:10","212":"2022-06-09 04:05:35"},
"invoice_id":2,"users":{"15":"2022-06-09 10:56:10","246":"2022-06-09 04:05:35"},
我想获取用户=“ 14”:
我尝试了php mongo查询
$data["users.0"] = new MongoDB\BSON\Regex("14");
$result = $collection->find($data, $option);
问题是 - 它的价值搜索。我只想在密钥中搜索。
请指导。
I want to to fetch row in Mongo on matching the subdocument in PHP Mongo.I want to achive result like
mysql query :- users like '"14:"' or invoice_id
="2"`
My structure in Mongo is
"invoice_id":0,"users":{"14":"2022-06-09 10:56:10","212":"2022-06-09 04:05:35"},
"invoice_id":2,"users":{"15":"2022-06-09 10:56:10","246":"2022-06-09 04:05:35"},
I want to fetch users = "14":
I tried PHP Mongo Query
$data["users.0"] = new MongoDB\BSON\Regex("14");
$result = $collection->find($data, $option);
The problem is - it search in value. I want to search in key only.
Please guide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是“存在”,
这为搜索结果提供了键“ 14”
The solution was "$exists"
This gives search result with Key "14"