Created
March 14, 2020 03:15
-
-
Save dj-nitehawk/e1dff86cb1e43725f9b79fde416f09bd to your computer and use it in GitHub Desktop.
find query with filter > sort > limit > project
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.Linq; | |
namespace StackOverFlow | |
{ | |
public class Item : Entity | |
{ | |
public int a { get; set; } | |
public int b { get; set; } | |
public int c { get; set; } | |
public int d { get; set; } | |
} | |
public static class Program | |
{ | |
private static void Main() | |
{ | |
new DB("test", "localhost"); | |
new Item | |
{ | |
a = 5, | |
b = 6, | |
c = 11, | |
d = 1 | |
}.Save(); | |
var id = DB.Find<Item, string>() | |
.Match(i => i.a == 5 && i.b == 6 && i.c == 11) | |
.Sort(i => i.d, Order.Descending) | |
.Limit(1) | |
.Project(i => i.ID) | |
.Execute() | |
.SingleOrDefault(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment