N1QL查询通过其定制版本更新数组元素

问题描述 投票:0回答:2

在发布数据的同时,我使用了escapeCSV来处理额外的逗号,但数据有一些额外的/“现在我想通过使用N1QL来更新内容,但是我被卡住了

    "School": [
    {
      "address": "\"257 Shyam Nagar, Indore\"",
      "name": "National Convent"
    }


  Required:-

   "School": [
    {
      "address": "257 Shyam Nagar, Indore",
      "name": "National Convent"
    }
couchbase
2个回答
1
投票

使用REPLACE()函数

UPDATE default d 
SET p.address = REPLACE(p.address, "\"","") FOR p IN d.School END 
WHERE ...;

0
投票

您需要在导入之前删除它们,N1QL需要有效的JSON。此外,您还可以使用单引号:

INSERT INTO `test` ( KEY, VALUE ) 
 VALUES 
 ( 
   'mykey2', 
    {
      'type': '"toy',
      "attributes": {
      'material': 'metal"',
      'color': 'red""',
      'weight': '200gr"',
      'height': '5cm',
      'width': '15cm'
    }
}

)

© www.soinside.com 2019 - 2024. All rights reserved.