我有以下文件。我正在编写一个API来将"dataTracking"
更新为true
或false
。我正在尝试基于"userID"
、"ulcaApiKey"
和"serviceProviderName"
进行更新。
{
"_id": {
"$oid": "64462ca4ff7e6dfc24d0eaeab"
},
"userID": "6a73afa4fc774dcdb28d5fffsd944511fD",
"email": "samsaw.somseeyou@gmail.com",
"firstName": "SAM SAW Master",
"password": "$2b$12$IMYAkfdXBruXJm75O9P79.cZZHTA0SB9fvJDTN.cg7Fwtu/VBg/JS",
"isVerified": true,
"isActive": true,
"roles": [
"SAMUEL-DATASETS-CONTRIBUTOR"
],
"apiKeyDetails": [
{
"appName": "apspDs",
"ulcaApiKey": "05ff4569ff-9cc1-4959-a39e-94e90e01de6s",
"createdTimestamp": "1681467785",
"serviceProviderKeys": [
{
"serviceProviderName": "maddyyyyys",
"dataTracking": "true",
"inferenceApiKey": {
"name": "Authorization",
"value": "VBM0sd4D82pQsdckvUwBwI62pCP7sYuniYcA4-5cGS4LF77dUSfhxp-yxdvo4qglzJ8"
}
},
{
"serviceProviderName": "somwthing",
"dataTracking": "false",
"inferenceApiKey": {
"name": "Authorization",
"value": "qi5tpTvGXsdckMDDiqCfMk_UQIKab8QeRdt3Gse3ZnEnsCtitnMZilU0aPIHCZl6xaC"
}
},
{
"serviceProviderName": "somehtingfandall",
"dataTracking": "false",
"inferenceApiKey": {
"name": "Authorsization",
"value": "qi5tpTsdfvGXkMDDiqCfMk_UQIKab8QeRdt3Gse3ZnEnsCtitnMZilU0aPIHCZl6xaC"
}
}
]
},
{
"appName": "app",
"ulcaApiKey": "05ff4569ff-9cc1-4959-a39e-94e90e01de66",
"createdTimestamp": "1681467785",
"serviceProviderKeys": [
{
"serviceProviderName": "maddyyyyy",
"dataTracking": "false",
"inferenceApiKey": {
"name": "Authorization",
"value": "VBM0sd4D82pQkvUwBwI62pCP7sYuniYcA4-5cGS4LF77dUSfhxp-yxdvo4qglzJ8"
}
},
{
"serviceProviderName": "AI4Bharat",
"dataTracking": "false",
"inferenceApiKey": {
"name": "Authorization",
"value": "qi5tpTvGXkMDDiqCfMk_UQIKab8QeRdt3Gse3ZnEnsCtitnMZilU0aPIHCZl6xaC"
}
}
]
},
{
"appName": "appDummy",
"ulcaApiKey": "05ff4569ff-9cc1-4959-a39e-94e90e01de6D",
"createdTimestamp": "1681467785",
"serviceProviderKeys": [
{
"serviceProviderName": "dummyMaddy",
"dataTracking": "true",
"inferenceApiKey": {
"name": "Authorization",
"value": "VBM0sd4D82pQkvUwBwI62pCP7sYuniYcA4-5cGS4LF77dUSfhxp-yxdvo4qglzJ8"
}
}
]
}
]
}
我尝试了下面的代码,但找不到结果。
db.getCollection("ulca-user").updateOne(
{
"userID": "6a73afa4fc774dcdb28d5fffsd944511fD",
"apiKeyDetails.ulcaApiKey": "05ff4569ff-9cc1-4959-a39e94e90e01de6s",
"apiKeyDetails.serviceProviderKeys.serviceProviderName": "maddyyyyys"
},
{
$set:{
"apiKeyDetails.serviceProviderKeys.dataTracking": "false"
}
}
)
如何使用"userID"
、"ulcaApiKey"
和"serviceProviderName"
更新"dataTracking"
?
1条答案
按热度按时间3zwtqj6y1#
就像@ray评论的那样,
"arrayFilters"
非常适合这个用例。你可以这么做。在mongoplayground.net上试试。