Question

I'm new to Couchdb just a few week back I git clone the couchdb app called sofa [what and app] . Over the week It was going great but suddenly today I stumble upon something.

Here what I meant when I browse the Sofa app and try to create a Post without the title it prompt with and alert box "The document could not be saved: The database could not be created, the file already exists." which was weird as looking at the source I found that the require (in validate_doc_update.js return its custom json error) something like in this format {"forbidden" : message }) with forbidden as key

  v.forbidden = function(message) {
      throw({forbidden : message})
  };

   v.require = function() {
        for (var i=0; i < arguments.length; i++) {
          var field = arguments[i];
          message = "The '"+field+"' field is required.";
          if (typeof newDoc[field] == "undefined") v.forbidden(message);
        };
      }; 

in validate_doc_update.js

if (newDoc.type == 'post') {
    if (!v.isAuthor()) {
      v.unauthorized("Only authors may edit posts.");
    }
    v.require("created_at", "author", "body", "format", "title");

inspecting the response state that the json returned was found to be different from the json had it would have been return by the above require function in validate_doc_update.js here is the json {"error":"file_exists","reason":"The database could not be created, the file already exists."}

This make be believe that the validation in validation_doc_update.js only execute during updating of document

to Prove this point I try to update a document without the title, expecting that it would return the error but surprisingly the document just got saved

so Here are my Question regarding all the Point I mention above

Does validate_doc_update.js "validate" work only during updation of document

if YES 
   then 
      how can I manage to succeed in updating a post without the error [Weird bypassing the Validation Completely] . +  How can execute validation on create of a document
if NO
   then 
     What is  the Error {"error":"file_exists","reason":"The database could not be created, the file already exists."} that is prevent a document to be saved  

Can anyone please share light on all the questions listed here

Was it helpful?

Solution

Yes, the validate_doc_update functions are run only when updating documents (include creation and deletion).

The function you show here will allow a document without a title as long as its type is not "post". If you could include the actual request you attempted, I could confirm it.

Finally, the ""The database could not be created" is because you are attempting to create the database (by doing PUT /dbname/ instead of PUT /dbname/docid, I would guess) when it already exists. Again, if you would include the actual request, I could confirm that too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top