2016-11-14 154 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 
}