Skip to content

Instantly share code, notes, and snippets.

@anandology
Created November 10, 2010 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/670374 to your computer and use it in GitHub Desktop.
Save anandology/670374 to your computer and use it in GitHub Desktop.
Python Script to add design document to couchdb database
import couchdb
view = {
"_id": "_design/seeds",
"fulltext": {
"by_seed": {
"index": """function(doc) {
if (doc.seeds) {
var d = new Document();
for (var i=0; i<doc.seeds.length; i++) {
d.add(doc.seeds[i].toLowerCase(), {"field": "seed", "index": "not_analyzed", "store": "yes", "analyzer": "keyword"});
}
d.add(doc.last_modified.value, {"field": "last_modified", "type": "string", "index": "not_analyzed", "store": "yes"});
return d;
}
return null;
}"""
}
}
}
def main(url):
db = couchdb.Database(url)
id = view['_id']
if id in db:
rev = db[id]['_rev']
view['_rev'] = rev
db[id] = view
if __name__ == "__main__":
import sys
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment