couchdb-net
couchdb-net copied to clipboard
Database Splitting + Convert --> Crash : Exception thrown: Call failed with status code 400 (Bad Request)
I have an object in CouchDB with a lot en fields. I just want to get light objects.
Is ok if I execute this command :
var couchDocuments = couchDatabase.Take(TAKE_LIMIT).Select(d => d.Id, d => d.Rev).ToList();
--> couchdb request parameters is :
"{\"limit\":1000,\"fields\":[\"_id\",\"_rev\"],\"selector\": {\"split_discriminator\":\"ExampleDataCouchDB\"}}"
But my object is not correctly typed
If I execute this command :
var couchDocuments2 = couchDatabase.Take(TAKE_LIMIT).Convert<TCouchDocument, TypedCouchDocumentBase>().ToList();
--> couchdb request parameters is :
"{\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}}\"typeMessage\",\"errorMessage\"],\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}}"
A comma is missing --> Crash : Exception thrown: 'Flurl.Http.FlurlHttpException' in System.Private.CoreLib.dll: 'Call failed with status code 400 (Bad Request): POST http://127.0.0.1:5984/example/_find'
If I execute this command :
var couchDocuments3 = couchDatabase.Take(TAKE_LIMIT).Convert<TCouchDocument, CouchDocumentBase>().ToList();
--> couchdb request parameters is :
"{\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}],\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}}"
No fields have been selected --> Crash : Exception thrown: 'Flurl.Http.FlurlHttpException' in System.Private.CoreLib.dll: 'Call failed with status code 400 (Bad Request): POST http://127.0.0.1:5984/example/_find'
Remark : In VisitConvertMethod method, why you have this condition : ".Where(p => p.DeclaringType != typeof(CouchDocument))" ? How can I get an object containing only the Id and the revision (Rev) ?
Remark 2 : For both "Convert" case, Take(1000) is not added on request
public class TypedCouchDocumentBase : CouchDocumentBase, IDto, EntityWithKeyAsString
{
virtual public string typeMessage { get; set; }
virtual public string errorMessage { get; set; }
public TypedCouchDocumentBase() {
}
}
public class CouchDocumentBase : CouchDocument
{
public CouchDocumentBase() {
}
}
using System;
using System.Threading.Tasks;
using CouchDB.Driver;
using CouchDB.Driver.Options;
using ExampleApi.Models;
using ExampleApi.ModelsCouchDB;
using Microsoft.Extensions.Logging;
namespace ExampleApi.CouchDB
{
public class CouchDBContext : CouchContext
{
public string DatabaseName = "example";
public CouchDatabase<ExampleDataCouchDB> ExampleDatas { get; set; }
public CouchDatabase<DesignDocument> ExampleDesign { get; set; }
protected override void OnDatabaseCreating(CouchDatabaseBuilder databaseBuilder)
{
databaseBuilder.Document<ExampleDataCouchDB>().ToDatabase(this.DatabaseName);
databaseBuilder.Document<DesignDocument>().ToDatabase(this.DatabaseName);
}
}
}
Hi, about the Where(p => p.DeclaringType != typeof(CouchDocument))
, it's probably because I didn't want to request stuff like _deleted, _attachments, _conflicts and split_discriminator. If you use that simpler DTO to read-only you can add [JsonProperty("_id"]
and not inherit from CouchDocument
.
As per remark 2 I added a unit test and I get
{
"limit": 1,
"fields": [
"name",
"age"
],
"selector": {}
}
so it seems to work