Skip to content

Instantly share code, notes, and snippets.

@atheken
Created July 11, 2010 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atheken/471224 to your computer and use it in GitHub Desktop.
Save atheken/471224 to your computer and use it in GitHub Desktop.
public Post GetMostRecentPost()
{
Post mostRecentPost;
using(var db = Mongo.Create("mongodb://localhost/BlogApp"))
{
var posts = db.GetCollection<Post>();
//create a LINQ queryable to search the DB.
var q = posts.AsQueryable();
//the ordering happens on the server and only one result will be returned.
mostRecentPost = q.OrderByDescending(y=>y.PostDate).FirstOrDefault();
}
return mostRecentPost;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment