Created
July 27, 2012 19:14
-
-
Save chrisdavies/3189919 to your computer and use it in GitHub Desktop.
Upsert and push an item onto an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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