> I could not find much material on upsert, and not sure whether it is
> mainly for incrementing counter values.
My understanding of Upsert is that it tries to update the row, if that fails,
insert the values. This is generically, the basic requirements of being an
upsert. Which seems to me to fit the description of Upsert in the mgo docs:
"Upsert finds a single document matching the provided selector document and
modifies it according to the change document. If no document matching the
selector is found, the change document is newly inserted instead."[1]
examples of upsert with mysql look like this:
INSERT INTO foo (a, b, c) VALUES(10, 20, 30) ON DUPLICATE KEY UPDATE
a = 10,
b = 20,
c = 30;
I think you might have been confused with the mongodb manual that shows
upserts with incrementing some counter. I think this was just a basic example
of upsert, because the updating page describes upsert as an argument to
Update() as this:
upsert - if this should be an "upsert"; that is, if the record does not exist,
insert it [2]
All this sounds like what you're doing and looking for.
Mike
[1] http://goneat.org/pkg/launchpad.net/mgo/#Collection.Upsert
[2] http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29
--
Life is like a sewer. What you get out of it depends on what you put into it.
-- Tom Lehrer