0

I have a million documents that I need to transform. Each document looks like this:

{
  "_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
    ]
  }
}

I'm trying to create a new property based on the "MS_DATE_TI" property for every record. What is the best way to do that?

THanks, Tyler

2 Answers2

0

Either build a little script in Python or use PouchDB directly in your browser.

Here's what the code should look like.

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
}
Alexis Côté
  • 3,670
  • 2
  • 14
  • 30
0

Thanks Alexis Côté. I ended up leveraging some of my python skills(I have no PouchDB skills(yet)):)

here's what I did:

Load python CouchDB library: https://pypi.python.org/pypi/CouchDB

Read over docs: http://pythonhosted.org/CouchDB/

Write a little script

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

Click run and go watch Matlock