Thanks.
Sample Code:
public bool UpsertFileStatus(FileStatus status)
{
MongoDatabase db =
MongoDatabase.Create(ConfigurationManager.ConnectionStrings[FileStatusDBName].ConnectionString);
SafeModeResult res =
db.GetCollection(FileStatusCollectionName).Save<FileStatus>(status,
SafeMode.True);
// Add to audit trail
BsonElement[] elements = new BsonElement[2];
elements[0] = new BsonElement("Status",
status.Status.ToString());
elements[1] = new BsonElement("UpdateUTC", DateTime.UtcNow);
BsonDocument historyEntry = new BsonDocument(elements);
db.GetCollection(FileStatusCollectionName).Update(Query.EQ("_id",
status.Filename), Update.Push("History", historyEntry));
return res.DocumentsAffected > 0;
}
On Dec 14, 6:24 pm, "Nat" <nat.lu...@gmail.com> wrote:
> Have you tried to turn profiling on to see what's getting executed? Everything looks ok except that your history can be overwritten by the "Save" function you had earlier in your code?
>
>
>
>
>
>
>
> -----Original Message-----
> From: Wade K <wka...@gmail.com>
> Sender: mongod...@googlegroups.com
> Date: Wed, 14 Dec 2011 16:12:01
> To: mongodb-user<mongod...@googlegroups.com>
> Reply-To: mongod...@googlegroups.com
> Subject: [mongodb-user] C# Driver - Update.Push() overwrites array.
>
> I am trying to add an audit trail to my documents using the
> Update.Push(). The general idea, is that every time the document is
> saved, i want to add an element to an array that will mark the status
> that the document was updated to and the timestamp that the update was
> made. However, when I run this, instead of appending the new entry to
> the end of the History array, the History array only holds a single
> element which is the latest (previous entries are overwritten.). So
> the query part is working, but the update portion is acting more like
> a $set. Am I missing an option parameter here? Manually running this
> in the shell seems to work fine.
>
> Thanks.
>
> Sample Code:
>
> public bool UpsertFileStatus(FileStatus status)
> {
> MongoDatabase db =
> MongoDatabase.Create(ConfigurationManager.ConnectionStrings[FileStatusDBNam e].ConnectionString);