How to name specific application fields in couchdb
I tried to add my own type-named _myappvar
and fields _myotherappvar
to documents to distinguish them from data fields. At first it worked, but at some point the futon starts to complain.
What's the correct way?
I am using couchdb 0.9.0, this may be old, but I will not update this iteration.
Edit: _*
Reserved for couchdb vars , I think . I could have picked something else, but is there any best practice or ho do you solve this?
Edit2: This is kind of hard for my application because it already works with these fields. I wonder under what circumstances I can keep the details that work and apply the new name for future fields.
a source to share
You're right. This explains the section "CouchDB Document Interface, Special Fields" .
Top-level fields may not start with _
.
CouchDB is relaxed, so the best way to do this is easiest for your application. About your specific changes:
-
One idea is to use a suffix
_
instead of a prefix. Another idea is a field.myapp
, which is an object (namespace) for your internal data. You can also combine them:{ "type": "the document type", "var1": "Normal variable 1", "var2": true, "myapp_": { "var": "Something internal", "othervar": null, } }
You can now link to
doc.myapp_.var
your maps, zoom out, etc. -
You have a choice. You can bite the bullet and change all the paperwork right now. I don't know your application, but I prefer this because you are playing with fire using a prefix
_
.However, you can also have both types of document and just teach your function
map()
how to handle both of them.function(doc) { if(doc.type == "the document type") { if(doc._myappvar) { emit(doc._id, doc._myappvar); // The old way } else if(doc.myapp_) { emit(doc._id, doc.myapp_.var); // The new way } } }
Good luck!
a source to share