Created
March 12, 2020 17:08
-
-
Save dj-nitehawk/b71e0a143422188f7ec39fa4ad9c68cb to your computer and use it in GitHub Desktop.
update with aggregation pipeline stage
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
using MongoDB.Entities; | |
using MongoDB.Entities.Core; | |
using System; | |
namespace StackOverFlow | |
{ | |
public class UnitTravelHistory : Entity | |
{ | |
public long JobDuration { get; set; } | |
public DateTime Start { get; set; } | |
public DateTime End { get; set; } | |
} | |
public static class Program | |
{ | |
private static void Main() | |
{ | |
new DB("test", "localhost"); | |
new UnitTravelHistory | |
{ | |
Start = DateTime.UtcNow.AddDays(-1), | |
End = DateTime.UtcNow | |
}.Save(); | |
DB.Update<UnitTravelHistory>() | |
.Match(_ => true) | |
.WithPipelineStage("{$set:{JobDuration:{$subtract:['$End','$Start']}}}") | |
.ExecutePipeline(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment