I need to create a Database with CouchDB and bind it together with C# for a school project. It should be with EF or something similar, so i found CouchDB.NET.
I set up the Database local and added some files like the example.
When i run the programm i get a Bad - Http Request 400 and it creates a random empty DB where.
Am I missing something essential? Or are there any other approaches for this problem?
Thank you in advance for your help!
Example of JSON File in CouchDB. Database is called "animals"
{
"_id": "someId",
"_rev" "somerev",
"species": "Mammal"
"name":"Dog",
"age": "10",
"food": "Meat"
}
}
After that i tried to implement the code on Github from the ReadMe and get the info from the inside a console.
Programm.cs
using CouchDB.Driver.Extensions;
using CouchDB.Driver.Query.Extensions;
namespace CouchDB
{
internal class Program
{
static async Task Main(string[] args)
{
// Usage
await using var context = new UserContext();
var animal = await context.Animals
.Where(r => r.Species == "Mammal")
.OrderByDescending(r => r.Name)
.ThenByDescending(r => r.Age)
.Select(r => r.Name, r => r.Age).ToListAsync();
foreach (var item in animal)
{
Console.WriteLine(item.Name);
}
}
}
}
UserContext.cs
using CouchDB.Driver;
using CouchDB.Driver.Options;
namespace CouchDB
{
public class UserContext : CouchContext
{
public CouchDatabase<Animal> Animals { get; set; }
protected override void OnConfiguring(CouchOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseEndpoint("http://localhost:5984/")
.EnsureDatabaseExists()
.UseBasicAuthentication(username: "admin", password: "admin");
}
}
}
Animal.cs
using CouchDB.Driver.Types;
namespace CouchDB
{
public class Animal : CouchDocument
{
public string Species { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Food { get; set; }
}
}