Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created August 26, 2017 17:56
Show Gist options
  • Select an option

  • Save JeremyLikness/bfd29e0fed5ac2bc896437e8dac82ffc to your computer and use it in GitHub Desktop.

Select an option

Save JeremyLikness/bfd29e0fed5ac2bc896437e8dac82ffc to your computer and use it in GitHub Desktop.
A strongly-typed MongoDB query
var projection = Builders<FoodItem>.Projection
.Include(fi => fi.FoodId)
.Include(fi => fi.FoodGroupId)
.Include(fi => fi.Description)
.Include(fi => fi.ShortDescription);
var query = db.GetCollection<FoodItem>(Collections.GetCollectionName<FoodItem>());
var findFluent = query.Find(fi => fi.Description.Contains(search));
var projectedQuery = findFluent.Limit(100).Project(projection);
await projectedQuery.ForEachAsync(item => { // do something });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment