On Sat, Apr 27, 2013 at 5:03 AM, <
mac...@gmail.com> wrote:
> I'm trying to Upsert a document and if it exists, increment the count by 1.
> I can do it in Mongo, but I don't have any idea how to nest the $inc
> correctly in mgo. The documentation doesn't specify and I wasn't able to
> find any other posts about it. Any advice?
The document you use with mgo is exactly the same one you use on the shell.
For example:
>> db.links.update({"link":"
www.example.com"}, {$set:{"slink":"g.g/1"},
>> $inc:{"count": 1}}, {upsert:true} )
type M map[string]interface{}
c := database.C("links").Upsert(M{"link": "
www.example.com"},
M{"$set": M{"slink": g.g/1"}, "$inc": M{"count": 1}})
> Go Query:
> change := mgo.Change{
This is building a request to send a findAndModify command to the
server, which isn't what you're doing in the shell.
gustavo @
http://niemeyer.net