Create an index (mongoquery)

Issue #4 resolved
David Rundle created an issue

http://docs.couchdb.org/en/2.0.0/api/database/find.html#db-index

to sort with a mongo query we need to be able to create an index.

  • create index on a ddoc
  • create a standalone index.

notes

  • DB -> design doc -> index.
  • no type support, so 2 indexes which index the "name" field are essentially the same.
  • using the design doc name we can group indexes, but a change will mean all in that design doc are re indexed

#initial thoughts

conventions

DDoc Name

for any strongly typed index, it will equal the full class name

Index name

if not supplied, it will equal the concatenation of the fields and sorts hashed.

#Possible API

Off the Database

Database.Index.Create<Person>(idx => 
{
    idx.Name ="custom name"; //optional
    idx.DesignDoc = "test1"; //optional
    idx.Field(x=> x.Name);
    idx.Field(x=> x.Age, Sort.Descending);
})

//OR

var idx = new Index(){
    Name = "",
    DesignDocument = "",
};
idx.Field("name", Sort.Asc);

Database.Index.Create(idx);

Class Map

class PersonMap : ClassMap<Person> 
{
    PersonMap()
    {
        Id(x=> x.Id);

        Index(idx => {
            idx.Name = "custom name";
            idx.DesignDoc = "test1"; //optional
            idx.Field(x=> x.Name);
            idx.Field(x=> x.Age, Sort.Descending);

        });
    }
}

Comments (7)

  1. David Rundle reporter

    above has been implemented (maybe slightly different), target to be released in 0.6.x

  2. Log in to comment