couchbase - 对 CouchBase 编程的热情
问题描述
我想获取对象数组中的 Couchbase 文档中的单个元素,但我能够获取对象数组
我尝试使用以下查询获取数组,'select countryDetails from test';
{
"type":"countries",
"docName":"CountryData",
"countryDetails":[
{
"name":"US",
"code":"+1",
"stateInfo":[
{
"name":"Florida",
"id":"1212"
},
{
"name":"NewYork",
"id":"1214"
}
]
},
{
"name":"France",
"code":"+33",
"stateInfo":[
{
"name":"Grand Est",
"id":"5212"
},
{
"name":"Brittany",
"id":"5214"
}
]
}
]
}
我尝试使用获取数组,select countryDetails from test;
我喜欢获取结果[ {"name" : "US", "code" : "+1" }, {"name" : "France", "code" : "+33"}]
解决方案
如果您投影 countryDetails 它会投影整个子对象。如果你需要子对象的一部分,你需要明确地投影它。
以下 ARRAY 构造将提供您期望的数据表示。
SELECT ARRAY {v.name,v.code} FOR v IN t.countryDetails END AS contryDetails
FROM test AS t
WHERE t.type = "countries";
推荐阅读
- r - R错误中的简单函数
- cplex - CPLEX 删除约束
- c++ - 使用 push_back 分配内存与构造特定大小的向量
- javascript - 让 CSS 按钮在单击时变为绿色并保持绿色
- mysql - 当条件不满足时,MySQL Force 'WHERE' 显示 null
- python - TensorFlow 的正则化器中的 scale 代表什么?
- visual-studio-code - 在“/Users/userName”中找不到名为“pubspec.yaml”的文件
- ios - 在 SWIFT 4 中将 JSON 数据移出本地范围
- django - Django:inlineformset '属性没有与之关联的文件' 错误
- mariadb - Mariadb 10.3.8:从 MariaDB 存储库安装,缺少文件?