Hi guys,
Can anyone please advise? I'm trying to add a value to an arrary in a
findandmodify, but get the following error message:
Cannot apply $addToSet modifier to non-array
The update is:
MongoCollection<Account> _accounts; // initialised elsewhere...
_accounts.FindAndModify(
Query
.EQ("_id", accountId),
null,
Update
.Set("Status", AccountStatus.Validated)
.AddToSet("Roles", Roles.VALIDATED)
);
The object is serialised as:
{ "_id" : ObjectId("4e0f5677f8419321981bd873"), "Status" : 2,
"Email" : "
te...@gmail.com", "HashedPassword" : "$2a
$10$TbzLuhVvCyRC7uOpyJ5og.BVNN.Tywa6
eeJiYy64z5IBFsKhp0NPG", "FirstName" : "Daniel", "LastName" : "Harman",
"Gender"
: 0, "DoB" : ISODate("1900-02-19T00:00:00Z"), "CreatedOn" :
ISODate("2011-07-02T
17:33:43.828Z"), "Roles" : null, "InvitedBy" : null }
from the following POCO:
public class Account
{
public ObjectId Id { get; set; }
public AccountStatus Status { get; set; }
public string Email { get; set; }
public string HashedPassword { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Gender Gender { get; set; }
[BsonDateTimeOptions(DateOnly = true)]
public DateTime DoB { get; set; }
public DateTime CreatedOn { get; set; }
public List<string> Roles { get; set; }
public List<ObjectId> InvitedBy { get; set; }
}
I'm on mongo 1.8.1 and driver 1.0.0.4098.
It seems to me the problem is that the array has been serialised as
empty rather than null, but would think the driver should be able to
cope?
Any ideas greatly appreciated.
Thanks,
Dan