Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update with aggregation pipeline stage
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