Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Created March 14, 2020 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj-nitehawk/e1dff86cb1e43725f9b79fde416f09bd to your computer and use it in GitHub Desktop.
Save dj-nitehawk/e1dff86cb1e43725f9b79fde416f09bd to your computer and use it in GitHub Desktop.
find query with filter > sort > limit > project
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