I\'m hoping I\'ve not gotten the wrong end of the stick here (as always the sitecore documentation is woeful!)
I wanted a way to store information against a visitor,
After a great deal of debugging, fiddling and testing I finally figured this out. My issue, it turned out, wasn't the writing to mongo it was in the reading back out of mongo once it had been written.
The sitecore documentation seems (as usual) to completely miss a rather fundamental part of the working of this. About a third of the way down the docs it states:
public EmployeeData() { base.EnsureAttribute(FIELD_EMPLOYEE_ID); } The "EnsureAttribute" method is the equivalent of declaring a value-type variable.
Ok, this is very misleading. What this EnsureAttribute appears to do is load the data for the facet into the current class from mongo. If you don't do this for every property in your facet then it does not set the value from the mongoDb! This was my mistake, I hadn't "ensured" every property in the class.
So what was happening is,
SC_ANALYTICS_GLOBAL_COOKIE does this for you)So the EnsureAttribute does not "declare a value type" (this is just totally wrong in my opinion) it loads the data out of mongodb and into the current Session.