You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Alexander Gabriel <al...@barbalex.ch> on 2011/05/15 21:34:33 UTC

updating document with $db.saveDoc: How come not anymore saved fields stay in the document?

Hi
I'm a new to java script and not a very experienced programmer so please
excuse stupid mistakes...

I am updating a document using this code:

$("#submitButton").live("click", function(event) {
var docId = "{{id}}";
$db.openDoc(docId, {
success: function(doc) {
doc.Modus = "einfach";
doc.Typ = "Beobachtung";
doc.User = User;
doc.bArtGruppe = $("select#bArtGruppe").val();
doc.bArtName = $("select#bArtName").val();
if ($("input#bArtId").val() != null){
doc.bArtId = $("input#bArtId").val();
}
if ($("input#bAutor").val()!=null){
doc.bAutor = $("input#bAutor").val();
}
if ($("input#oXKoord").val()!=null){
doc.oXKoord = $("input#oXKoord").val();
}
... and e few more ...
saveDocument(doc);
},
error: function() {
alert("Diese Beobachtung kann nicht geƶffnet werden: " + docId);
}
});
});

function saveDocument(document)
{
$db.saveDoc(document, {
success: function() {
window.open("../../index.html", target="_self");
},
error: function() {
alert("Beobachtung kann nicht gespeichert werden: " + document._id + ", " +
document.bArtName);
}
});
}

I know for sure that doc.oXKoord (for example) is not set when the input has
no value (I placed an alert inside the if. It only alerts, wehn the input
has a value).

What I dont understand is why doc.oXKoord stays in the document and keeps
the previous value. All the set values are updated and also the rev.

Unfortunately allmost all the documentation I could find so far is on put
and post, not on $db.saveDoc. With put and post, I read in the documentation
that if you update a document and you want do keep a field-value, you have
to save it again. And I could not find any way to remove a single
field-value without saving a new document.

Am I doing something wrong?
Is there a good documentation for the $db methods? (I know
http://arandomurl.com/random/jquery.couch.js-docs/symbols/$.couch.db.html for
instance. But real examples would be very helfpul).

Thanks for any help!

Alexander Gabriel

Re: updating document with $db.saveDoc: How come not anymore saved fields stay in the document?

Posted by Alexander Gabriel <al...@barbalex.ch>.
wow, that was a great help! Thanks a lot, Mark Hahn!


 Alexander Gabriel


2011/5/15 Mark Hahn <ma...@boutiquing.com>

> delete doc.oXKoord
> db.saveDoc doc
>
> will remove oXKoord
>
> On Sun, May 15, 2011 at 12:34 PM, Alexander Gabriel <al...@barbalex.ch>
> wrote:
> > doc.oXKoord
>
>
>
> --
> Mark Hahn
> Website Manager
> mark@boutiquing.com
> 949-229-1012
>

Re: updating document with $db.saveDoc: How come not anymore saved fields stay in the document?

Posted by Mark Hahn <ma...@boutiquing.com>.
delete doc.oXKoord
db.saveDoc doc

will remove oXKoord

On Sun, May 15, 2011 at 12:34 PM, Alexander Gabriel <al...@barbalex.ch> wrote:
> doc.oXKoord



-- 
Mark Hahn
Website Manager
mark@boutiquing.com
949-229-1012