This project has moved and is read-only. For the latest updates, please go here.

Text Indexes and Capped Collections

May 6, 2014 at 5:46 AM

Is there a way to create text indexes and capped collections?
I've found the MongoRepositoryManager, but it doesn't appear to support either.

May 6, 2014 at 10:44 AM
Edited May 6, 2014 at 11:07 AM
You can easily implement a capped repository:
using MongoDB.Driver.Builders;
using MongoRepository;

public class CappedRepository<T> : MongoRepository<T>
        where T : Entity
    public CappedRepository(long maxSize, long maxDocuments)
        var options = CollectionOptions

        var db = this.collection.Database;

        if (!db.CollectionExists(this.Collection.Name))
            db.CreateCollection(this.Collection.Name, options);
Then do:
var myCappedRepo = new CappedRepository<Foo>(100, 50);
The text-index can be implemented in a similar way:
using MongoDB.Driver.Builders;
using MongoRepository;

public class MyRepository : MongoRepository<Foo>
    public MyRepository()
        this.collection.EnsureIndex(new IndexKeysBuilder().Text("some-field-name"));
Note that for both cases (capped collection and text-index) you need to reference some MongoDB's actual driver.
Marked as answer by Cyonix on 5/6/2014 at 3:27 PM
May 6, 2014 at 11:27 PM
Great, thanks for that!