public async Task InsertsOne() { /*[{"name": "venus flytrap", "sunlight": "full", "color": "white", "type": "perennial", "_partition": "Store 42"}, * {"name": "sweet basil", "sunlight": "partial", "color": "green", "type": "annual", "_partition": "Store 42"}, * {"name": "thai basil", "sunlight": "partial", "color": "green", "type": "perennial", "_partition": "Store 42"}, * {"name": "helianthus", "sunlight": "full", "color": "yellow", "type": "annual", "_partition": "Store 42"}, * {"name": "petunia", "sunlight": "full", "color": "purple", "type": "annual", "_partition": "Store 47"}]*/ // :code-block-start: mongo-insert-one var plant = new Plant { Name = "Venus Flytrap", Sunlight = Sunlight.full, Color = PlantColor.white, Type = PlantType.perennial, Partition = "Store 42" }; var insertResult = await plantsCollection.InsertOneAsync(plant); var newId = insertResult.InsertedId; Assert.IsNotNull(plant.Id); Assert.AreEqual(newId, plant.Id); // :code-block-end: }
public async Task InsertsOne() { var plant = new Plant { Name = "Venus Flytrap", Sunlight = Sunlight.Full, Color = PlantColor.White, Type = PlantType.Perennial, Partition = "Store 42" }; var insertResult = await plantsCollection.InsertOneAsync(plant); var newId = insertResult.InsertedId; }
public async Task InsertsOne() { // :code-block-start: mongo-insert-one var plant = new Plant { Name = "Venus Flytrap", Sunlight = Sunlight.Full.ToString(), Color = PlantColor.White.ToString(), Type = PlantType.Perennial.ToString(), Partition = "Store 42" }; var insertResult = await plantsCollection.InsertOneAsync(plant); var newId = insertResult.InsertedId; // :code-block-end: }
public async Task Creates() { app = App.Create(myRealmAppId); user = await app.LogInAsync(Credentials.Anonymous()); mongoClient = user.GetMongoClient("mongodb-atlas"); dbTracker = mongoClient.GetDatabase("tracker"); cudCollection = dbTracker.GetCollection <CustomUserData>("user_data"); var cud = new CustomUserData(user.Id) { FavoriteColor = "pink", LocalTimeZone = "+8", IsCool = true }; var insertResult = await cudCollection.InsertOneAsync(cud); Assert.AreEqual(user.Id, insertResult.InsertedId); }