2016-11-14 118 views
0

我有一百万个需要转换的文档。每个文件看起来像这样:基于现有属性的couchdb文档属性:批量更新

{ 
    "_id": "00082786797c0a31ab8b5e67fb0000dc", 
    "_rev": "3-d67692b1c94b936ae913bf7ea4896bed", 
    "type": "Feature", 
    "properties": { 
    "timestamp": "2015-08-03 21:26:48.000", 
    "status": "on", 
    "avstatus": null, 
    "speed": "38", 
    "MS_DATE_TI": 1438576728000, 
    "STR_DATE_T": "1438576728000" 
    }, 
    "geometry": { 
    "type": "Point", 
    "coordinates": [ 
     -8784866.197274148, 
     4296254.156268783 
    ] 
    } 
} 

我想创建一个基于每个记录的“MS_DATE_TI”属性的新属性。什么是最好的方式来做到这一点?

感谢,泰勒

回答

0

谢谢AlexisCôté。我结束了利用我的一些Python的技能(我没有PouchDB技能(还)):)

这里就是我所做的:

负载蟒蛇CouchDB的库: https://pypi.python.org/pypi/CouchDB

阅读过的文档: http://pythonhosted.org/CouchDB/

写小脚本

import couchdb 
couch = couchdb.Server() 
db = couch['avl_multi_doc'] 
for id in db: 
    doc = db[id] 
    print doc['properties']['MS_DATE_TI'] 
    doc['time'] = doc['properties']['MS_DATE_TI'] 
    db[doc.id] = doc 

点击[R联合国去看Matlock

0

无论是在Python中建立一个小的脚本或直接在浏览器中使用PouchDB。

下面是代码的样子。

var n; //The number of documents to get for every bulkget. Use it as a limit 
var lastKey; //The key used as startkey_docid parameter 

while(true){ 
    //AllDocs to get N documents starting from lastkey 
    //Update the documents locally by doing a loop 
    //Send the updates to the server 
    //If response.rows < limit, you probably have updated all the lines so break the loop 
}