gpt4 book ai didi

pouchdb - 在 PouchDB 中加入(链接)文档

转载 作者:行者123 更新时间:2023-12-05 04:06:42 26 4
gpt4 key购买 nike

我使用 CouchDB 作为后端,使用 PouchDB 在 vuejs 应用程序中查询/同步数据库。

我有 4 种不同类型的文档都存储在一个数据库中,如上所示:

{
"_id": "patientmed_001",
"_rev": "1-b892ba78a095627af8aef65ac279cc84",
"doctype": "patient_medication",
"patient_id": "patient_001",
"visit_id": "patvisit_001",
"medicine_id": "med_001",
"quantity": "1",
"startdate": "20180101",
"enddate": "20180201"
}

{
"_id": "patvisit_001",
"_rev": "1-f071319f39f4f5df2a1e8214ccc46453",
"doctype": "patientvisit",
"patient_id": "patient_001",
"visitdate": "20010910",
"complaint": "fever",
"doctor_attended": "doctor_001",
"feespaid": "300"
}

{
"_id": "med_001",
"_rev": "1-030b39b7773de39fb6a178d77d3d6461",
"doctype": "medicine",
"batch": "001",
"batchdate": "20010910",
"expirydate": "20021010",
"unit": "bottle",
"type": "pills",
"vendor": "xyz",
"curr_stock": "20",
"cost": "200",
"lastreplenished": "20180101"
}

{
"_id": "patient_001",
"_rev": "1-1772d5ff54c46b15642d0b10e5f3906d",
"doctype": "patient",
"FirstName": "Test",
"LastName": "Patient3",
"Gender": "Male",
"DOB": "19401010",
"Address1": "999, XYZ Street",
"Address2": "ABC avenue",
"City": "London",
"Pincode": "AB1CD2",
"State": "BlahBlah",
"Country": "UK",
"Mobile": "001182919112"
}

是否可以通过传递 patient_id 在 PouchDB 中查询以从其他文档中获取相关信息,类似于 RDBMS 中的连接? (即

SELECT PatMed.*, PatVisit.*, Patient.* from Patient P
INNER JOIN PatientVisit PatVisit on P.ID = PatVisit.Patient_ID
INNER JOIN PatientMed PatMed on PatVisit.ID = PatMed.VisitID
...

最佳答案

我对 RDBMS 不太熟悉,我不确定我是否理解你的问题,但你可以创建如下所示的索引。

var myIndex = {
_id: '_design/my_index',
views: {
'my_index': {
map: function (doc) {
if(doc.patient_id){
// emit patient_id as key and doc as value
emit(doc.patient_id, doc);
}
}.toString()
}
}
};

现在您可以PUT 并查询上述索引以查找所有patient_id 字段等于特定值的文档:

// save the design doc view and the corresponding index
pouch.put(myIndex).then(() => {
// query the index
return pouch.query('my_index', {key: 'patient_001'});
}).then(result => {
// found docs with patient_id === 'patient_001'
console.log(result)
});

关于pouchdb - 在 PouchDB 中加入(链接)文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49571935/

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