我想将电话号码对象添加到我的个人文档中,以将它们保存在数组中。到目前为止,我还不错,向阵列添加新的手机文档没有问题。如果我想通过子文档更新数组中的文档,在这里会有些棘手,我需要知道数组中的索引,这就是我关心的问题。 Couchbase允许用户追加,前置到数组中。因此,即使这样我在最初检索数组时也可以获取数组索引,仍然有轻微的机会有人可能将新元素推入数组,这可能会更改索引。因此,在我更新或删除任何数组对象之前,需要使用CAS。 因此,有一种方法可以克服所有这些限制,并且仍然避免多次往返。
这是我的文档的样子
{
"type": "Lead",
"person": [
{
"id": 1,
"first_name": "Tom",
"middle_name": "M",
"last_name": "Miller",
"title": "Dr.",
"suffix": "II",
"gender": "m",
"dob": "07/12/1978",
"email": [
{
"id": 1,
"email_address": "tom@email.com",
"default": "yes"
},
{
"id": 2,
"email_address": "tom@email.com"
}
],
"phone": [
{
"id": 1,
"country": "+1",
"phone_number": 2135551212,
"ext": "",
"type": "mobile",
"sms": "yes",
"default": "yes"
},
{
"id": 2,
"country": "+1",
"phone_number": 2135554444,
"ext": 455,
"type": "office",
"sms": "no"
}
]
}
],
"home_address": {
"street_address": "28812 Miller Ave",
"city": "Los Angeles",
"state": "CA",
"zip": 90017,
"country": "US"
},
"search_info": {
"min_beds": 3,
"min_bath": 2.5,
"min_garage": 2,
"garage_type": "any",
"pool": "yes",
"min_sqft": 2500,
"max_sqft": 3500,
"min_lot_size": 10000,
"max_lot_size": 15000,
"max_storey": 1,
"notes": "Wants a fixer upper"
}
}