简体   繁体   English

通过另一个中的id从一个Sofadb文档中提取数据(Python)

[英]Pull data from one couchdb doc via ids in another (Python)

I have two databases in CouchDB - DB1's documents are user data - name, email address, username, password but within one field that I store a list of the ID's saved in DB2 where user projects are saved (containing a username field and some Textfields. 我在CouchDB中有两个数据库-DB1的文档是用户数据-名称,电子邮件地址,用户名,密码,但是在一个字段中存储了ID2的列表,该ID保存在保存用户项目的DB2中(包含用户名字段和一些文本字段)。

    Example DB1 Document (Users)

       {
   "_id": "bobsmith1000",
   "_rev": "83-1e00173cac0e736c9988d3addac403de",
   "first_name": "Bob",
   "password": "$2a$12$sdZUkkyDnDePQFNarTTgyuUZS6DL13JvBk/k9iUa5jh08gWAS5hpm",
   "second_name": "Smith",
   "urls": null,
   "email": "bob@smith.com",
   "projects": [
       "ee5ccf56da22121fd71d892dbe051746",
       "ee5ccf56da22121fd71d892dbe0526bb",
       "ee5ccf56da22121fd71d892dbe053433",
       "ee5ccf56da22121fd71d892dbe056c71",
       "ee5ccf56da22121fd71d892dbe0579c3",
       "ee5ccf56da22121fd71d892dbe05930d"
   ]
}

Example DB2 Document (Projects)

{
   "_id": "ee5ccf56da22121fd71d892dbe05930d",
   "_rev": "1-c923fbe9de82318980c7778c4c089321",
   "url": "http://harkmastering.s3.amazonaws.com/testprojects/testfolder.zip",
   "username": "bobsmith1000",
   "time": "2010-10-29 07:13:47.377085",
   "file_size": "5.2 MB"
}

I am trying to write a view in Python (using the Flask web framework and Python Couchdb library) that will check db1, grab all the project ids, and then go to db2 and in a batch way pull out the url, time, filesize for each document with matching ids so I can can place that data in a table. 我正在尝试使用Python(使用Flask Web框架和Python Couchdb库)编写一个视图,该视图将检查db1,获取所有项目ID,然后转到db2,并以批处理的方式提取URL,时间和文件大小每个具有匹配ID的文档,这样我就可以将该数据放在表格中。

I only began programming earlier this year and this involves techniques that I can only imagine. 我今年年初才开始编程,这涉及到我只能想象的技术。 Can anyone help me find a solution? 谁能帮我找到解决方案?

Kind thanks 谢谢

Unless you have great reasons to split your docs in different dbs, that seems like is not the case according to your question, them you should keep them all on the same database and have some property on the docs to identify their type (like a "type: user" and "type: project"). 除非您有充分的理由将文档拆分到不同的数据库中,否则根据您的问题似乎不是这样,您应该将它们全部保存在同一数据库中,并在文档上具有一些属性以标识其类型(例如“类型:用户”和“类型:项目”)。

That way you can get the desired result on a single couchdb view without too much trouble. 这样,您就可以在一个榻榻米视图上获得理想的结果,而不会遇到太多麻烦。 In your view map function you will just need to emit keys like ["username",0] and ["username","projectname"]. 在视图功能中,您只需要发出诸如[“ username”,0]和[“ username”,“ projectname”]的键即可。 In Javascript that would be: 用Javascript将是:

function(doc) {
 if (doc.type == "user") {
  emit([doc._id,0],null);
 } else if(doc.type == "project") {
  emit([doc.username,doc._id],null);
 }
}

Them you can query that view and have an organized set of documents. 您可以查询该视图并拥有一组有组织的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Python中的字典中拉出彼此不相等的随机键 - Pull random keys from dictionary in Python that are not equal to one another 使用日期列表将数据从一个DataFrame拉入Pandas中的另一个 - Using a list of dates to pull data from one DataFrame into another in Pandas 如何通过 HTTP 将数据从一个项目(Python)发送到另一个项目(Java)? - How do I send data from one project (Python) to another project (Java) via HTTP? 如何通过 python 套接字程序将数据从一台计算机发送到同一 WiFi 网络上的另一台设备? - How to send the data from one computer to another device on the same WiFi network via python socket program? 通过UDP(python)从另一软件接收数据时,为什么一个软件会变慢? - Why does one software slow down when receiving data from another via UDP (python)? 通过flask / python以HTML显示来自ouchDB的图像附件 - display image attach from couchDB in html via flask/python 使用python中具有唯一ID的另一个帧从另一个具有重复ID的数据帧中查找值 - Find the values from another data frame with repetitive ids using another frame with unique id in python Python 3,将数据从一个函数传递到另一个函数 - Python 3, Passing data from one function to another 将数据从 python 页面发送到另一个页面 - Send data from a python page to another one 将数据从一个 python 文件发送到另一个文件 - Send data from one python file to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM