Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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