$set updates with structs work fine.
db := s.MgoSuite.Session.DB("juju") coll := db.C("coll") runner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: db}) err := runner.RunTransaction([]txn.Op{{ C: "coll", Id: "id", Insert: wtfDoc{"ping", "pong"}, }}) c.Assert(err, gc.IsNil)
for i := 0; i < 3; i++ { var current map[string]interface{} err = coll.FindId("id").One(¤t) c.Logf("doc looks like: %#v", current) err := runner.RunTransaction([]txn.Op{{ C: "coll", Id: "id", Update: bson.D{{"$set", wtfDoc{fmt.Sprintf("ping%d", i), fmt.Sprintf("ping%d", i)}}}, }}) c.Assert(err, jc.ErrorIsNil) }
...produces:
doc looks like: map[string]interface {}{"foo":"ping", "bar":"pong", "_id":"id", "txn-revno":2, "txn-queue":[]interface {}{"55a756237f78f24806000005_44d766e0"}} doc looks like: map[string]interface {}{"_id":"id", "bar":"ping0", "foo":"ping0", "txn-queue":[]interface {}{"55a756237f78f24806000006_89829a2c"}, "txn-revno":3} doc looks like: map[string]interface {}{"_id":"id", "bar":"ping1", "foo":"ping1", "txn-queue":[]interface {}{"55a756237f78f24806000007_7b3c6b7b"}, "txn-revno":4}
...as expected.
You definitely don't want to use $set with a struct that defines txn-queue or txn-revno though...
$set updates with structs work fine.
db := s.MgoSuite. Session. DB("juju" ) NewRunner( jujutxn. RunnerParams{ Database: db}) RunTransaction( []txn.Op{ {
coll := db.C("coll")
runner := jujutxn.
err := runner.
C: "coll",
Id: "id",
Insert: wtfDoc{"ping", "pong"},
}})
c.Assert(err, gc.IsNil)
for i := 0; i < 3; i++ { interface{ } "id").One( ¤t) RunTransaction( []txn.Op{ { fmt.Sprintf( "ping%d" , i), fmt.Sprintf( "ping%d" , i)}}},
var current map[string]
err = coll.FindId(
c.Logf("doc looks like: %#v", current)
err := runner.
C: "coll",
Id: "id",
Update: bson.D{{"$set", wtfDoc{
}})
c.Assert(err, jc.ErrorIsNil)
}
...produces:
doc looks like: map[string] interface {}{"foo":"ping", "bar":"pong", "_id":"id", "txn-revno":2, "txn-queue" :[]interface {}{"55a756237f7 8f24806000005_ 44d766e0" }} interface {}{"_id":"id", "bar":"ping0", "foo":"ping0", "txn-queue" :[]interface {}{"55a756237f7 8f24806000006_ 89829a2c" }, "txn-revno":3} interface {}{"_id":"id", "bar":"ping1", "foo":"ping1", "txn-queue" :[]interface {}{"55a756237f7 8f24806000007_ 7b3c6b7b" }, "txn-revno":4}
doc looks like: map[string]
doc looks like: map[string]
...as expected.
You definitely don't want to use $set with a struct that defines txn-queue or txn-revno though...