Skip to content

Instantly share code, notes, and snippets.

@efbenson
Created December 5, 2012 20:19
Show Gist options
  • Save efbenson/4219145 to your computer and use it in GitHub Desktop.
Save efbenson/4219145 to your computer and use it in GitHub Desktop.
//CODE in project
Facility.AddIndex(f => f.Locations);
LookupMetadata.AddIndex(f => new {f.TypeFullName, f.Data.DisplayText});
//CODE in library
public void AddIndex(Expression<Func<T, object>> indexKey, string indexName = null, bool isUnique = false, bool descending = false)
{
if (string.IsNullOrEmpty(indexName))
{
indexName = typeof(T).Name + "_Index_" + ObjectId.GenerateNewId();
}
// TODO: Make indexKey into a CSV string?
var keys = indexKey......
var keys = IndexKeys.Ascending(keys);
var options = IndexOptions.SetName(indexName).SetUnique(isUnique);
this.GetMongoCollection().CreateIndex(keys, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment