Can .NET (managed code) read and write to CouchDB?
I would like to build a part of my project that does document management using CouchDB
Little late to the game but there's an open source project for a new driver written in C# over the async HTTP Client and by default Newtonsoft's JSON.Net for serialization (switchable). MyCouch - Simple async CouchDb client for .Net.
A Getting started post exists here: http://danielwertheim.se/get-up-and-running-with-couchdb-and-c-using-mycouch-on-windows/
CouchDB's wiki has a list of API for C# (with their features) if you want the latest status : http://wiki.apache.org/couchdb/Getting_started_with_C%23
I recommend the CouchDb.Repository.Helper package. It is comprehensive and allows you to create your queries in XML files with parse of dynamic parameters according to values of variables or properties of objects.
I had the same need and after evaluating the options available, to meet the requirements of my application, I created these components that helped me a lot and maybe they can help you and also others. I make it clear that I have no intention of promoting myself here, just sharing something that may be useful.
The detailed explanation of how to configure and use it is on github.
Link: Nuget Package | Github
Example of use for retrieving documents with mango-querie:
IList<User> users;
var sts = new List<String> { "ACTIVE", "LOCKED" };
using (UserRepository db = new UserRepository())
{
var query = db.FindOf("list-status", new { id = "OwnerIdloop.user.7", statuses = sts });
users = db.List<User>(query);
}
Array.ForEach(users.ToArray(), Console.WriteLine);
Example of adding documents:
User user = createUser("email@email.com");
using (UserRepository db = new UserRepository())
{
var result = db.Insert<User>(user); // add document and return instance changed with operation revision id
Console.WriteLine(result.Revision);
}
Example of changing documents:
using (UserRepository db = new UserRepository())
{
// Load document data by ID
var user = db.Get<User>("email@email.com");
user.Name = user.Name + "::CHANGED";
var result = db.Update<User>(user); // update document and return instance changed with operation revision id
Console.WriteLine(result.Revision);
}
Example of deleting documents:
using (UserRepository db = new UserRepository())
{
// Load document data by ID
var user = db.Get<User>("email@email.com");
var result = db.Delete<User>(user); // delete document from database. Return true case sucess or false case not deleted
Console.WriteLine($"Sucesso: {result}");
}
Hope this helps!
Its a late answer, but do check out Hammock. It's active and going into production use on several projects soon and is receiving regular updates and fixes. Besides basic object persistence, Hammock gives you:
Repository<>
class that helps bring your queries/views (i.e. _Design doc) together with your c# application code. Repositories are responsible for maintaining _design docs, and this helps keep CouchDB views from feeling like stored procs.also take a look at divan - a light-weight wrapper for the cdb api
Given that you generally communicate with CouchDB over REST and JSON, I'd imagine it wouldn't be too hard to use JSON.NET and the normal WebClient/HttpWebRequest classes to do it. I haven't tried it myself, mind you...