Created
June 9, 2015 17:34
-
-
Save craiggwilson/f7145d6b00beaf9d0bdb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using MongoDB.Bson; | |
using MongoDB.Driver; | |
using MongoDB.Bson.Serialization.Attributes; | |
class Entity | |
{ | |
public ObjectId Id { get; set; } | |
public string Prop1 { get; set; } | |
public List<EmbeddedEntity> Embeds { get; set; } | |
public Entity() | |
{ | |
Embeds = new List<EmbeddedEntity>(); | |
} | |
} | |
class EmbeddedEntity | |
{ | |
public string Prop2 { get; set; } | |
} | |
var client = new MongoClient(); | |
var db = client.GetDatabase("test"); | |
var col = db.GetCollection<Entity>("entities"); | |
db.DropCollectionAsync("entities").Wait(); | |
var entity = new Entity { Prop1 = "Yes!" }; | |
col.InsertOneAsync(entity).Wait(); | |
var update = Builders<Entity>.Update.Push(x => x.Embeds, new EmbeddedEntity { Prop2 = "No!!!" }); | |
col.UpdateOneAsync(x => x.Id == entity.Id, update).Wait(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment