gpt4 book ai didi

MongoDB - 从对象内的数组中查找数据

转载 作者:可可西里 更新时间:2023-11-01 10:22:57 26 4
gpt4 key购买 nike

我的数据库格式如下

{
"_id" : ObjectId("56fc92adcf908c9f296e5885"),
"_class" : "com.abc.ppm.dto.AccessAttemptDTO",
"url" : "/myProject/edit",
"ipAddress" : "127.0.0.1",
"param" : {
"iecode" : [
"P1234"
],
"id" : [
"5696578c6d34f835dc632fdd "
]
},
"accessTime" : "30-3-2016 10:59:57",
"email" : "abc@gmail.com",
"entity" : "admin",
"entityCode" : ""
},

{
"_id" : ObjectId("56fc92adcf908c9f296e5887"),
"_class" : "com.abc.ppm.dto.AccessAttemptDTO",
"url" : "/myProject/edit",
"ipAddress" : "127.0.0.1",
"param" : {
"iecode" : [
"P1122"
],
"id" : [
"5696578c6d34f835dc632fdd "
]
},
"accessTime" : "30-3-2016 10:59:57",
"email" : "abc@gmail.com",
"entity" : "admin",
"entityCode" : ""

现在我想找到iecode 为'P1234' 的所有条目。我怎么做? (注意:iecodes 值以字符串数组格式存储。)

最佳答案

你可以这样写查询:

db.collectionName.find({"param.iecode": "P1234"})

关于MongoDB - 从对象内的数组中查找数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37087048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com