Welcome Guest, you are in: Login

dbones docs


Navigation (ArmChair)

Search the wiki

Armchair provides limited Linq support. please read the overview.

For the best experience in querying please look into Indexes and ClassMaps. this page will point out when you will need either concept.


This page looks a little more into the LINQ support supplied by ArmChair.

CouchDB 2.0 add Mongo Query support, the more you understand this API the better you will understand what can be accomplished via the LINQ to Mongo interface. So its recommended to have a read of this page: http://docs.couchdb.org/en/2.0.0/api/database/find.html

How it works

The Linq query is converted into a Mongo Query Object and then executed as normal.


For more examples of what can be done, please refer to the unit tests which are located in arm chair / src / ArmChair.Tests / Linq / in the source code

Strongly Typed

All queries take the Type into account, and will return all objects of that type and any object which inherit it.

//returns first 50 objects it finds in the database.
var fiftyObjects = session.Query<object>().Take(50);

//filters for the first 50 Person objects in the database
var fiftyPeople = session.Query<Person>().Take(50);

in order to fully support this functionality you need to inform ArmChair of all persist-able types at setup.

//scan for all the types
var types = typeof(Person).Assembly.GetTypes().Where(x => typeof(EntityRoot).IsAssignableFrom(x));
//now register them


using the take and skip, you can apply the usual paging functionality.

var pagedListOfPeople = session.Query<Person>().Skip(100).Take(50);


an index needs to be setup, please consult the CounchDb docs for more information on how to do that.

var peopleOrderedByName = session.Query<Person>().OrderBy(x=>x.Name);

Applying Indexes

(not tested at the moment via the Linq interface.)

you can see in the Query Method we can pass in the index name.

results = session.Query<Person>("design-document-name","index-name").OrderBy(x=>x.Name);

If these are supplied then, by default, the best index will be selected. as detailed in the Couchdb docs.


regex has been supported via the StartsWith, EndsWith and Contains methods.

var allPeopleWithNamesWitchStartWithD = session.Query<Person>().Where(x=>x.Name.StartsWith("d"));

Multiple Where Clauses

a query can have many where clauses, each of these with be and-ed together.

var results = session.Query<Person>()
                     .Where(x=>x.Age < 50);

this will filter for

type is Person AND Name starts with "d" AND age < 50

dbones docs, is a sub-site of dbones.co.uk, all its content belongs to dbones.co.uk, this also includes logo's.