Skip to content

Instantly share code, notes, and snippets.

@chrisdavies
Created July 27, 2012 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdavies/3189919 to your computer and use it in GitHub Desktop.
Save chrisdavies/3189919 to your computer and use it in GitHub Desktop.
Upsert and push an item onto an array
var query = Query.And(
Query.EQ("_id", post.Id),
Query.NE("Comments._id", comment.Id));
var options = new MongoUpdateOptions {
Flags = UpdateFlags.Upsert,
SafeMode = SafeMode.False
};
var update = Update.AddToSetWrapped("Comments", comment)
.Inc("TotalComments", 1);
DataStore.GetCollection<CommentThread>()
.Update(query, update, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment