matteobortolazzo / couchdb-net Goto Github PK
View Code? Open in Web Editor NEWEF Core-like CouchDB experience for .NET!
License: MIT License
EF Core-like CouchDB experience for .NET!
License: MIT License
the documentation says that we need an index for min/max
WARN: Since Max and Min use sort, an index must be created.
how do you do it?
The Linq statement, 'Select' is broken due to constrained linq extensions.
For instance:
var ids = await _database
.Select(doc => doc.Id)
.ToListAsync();
Generates a compiler error, because the return type 'string' is not of type 'CouchDocument'.
Hi!
I use couch db database with multiple models from F#, I was wondering:
I assume I can use diff "databases" that are the same but with different TSource.:
var rebels = client.GetDatabase<Rebel>("StarWars");
var clones = client.GetDatabase<Clone>("StarWars");
Not sure about your conventions, but ICouchDatabase<T>.AddOrUpdate
does not have Async
suffix, so it is not consistent with other methods in the ICouchDatabase<T>
.
@matteobortolazzo Why camelize the member names in
In my case, the data in couch is all pascal case, so queries no longer find anything. I'm going to work around it locally by removing that, but it feels intentional, so I don't think I should PR without discussion. It feels like at least an option is necessary here
It looks like the query optimizer could be improved to handle short circuited logical And/Or expressions. Currently the optimizer/translator will generate invalid mango queries.
Example:
bool useFilter = true; //from user input...
var mango = _database.Where(doc => useFilter && doc.MyField == "foobar").ToString();
The query generated is
{
"$and" : [
true,
"$eq": {
"myfield":"foobar"
}
]
}
I would have expected the optimizer to 'prune' all the 'true/false' branches for And/Or. Instead, the above query returns nothing.
The workaround is to do this:
if (useFilter) //use constant outside of expression
{
_database.Where(...);
}
It works, but it's not intuitive to the user.
Is't possibile to use this driver to receive new data from _changes?
LoginAsync
is synchronously called in OnBeforeCall
when using AuthenticationType.Cookie
and token is expired. What about to use FlurlHttpSettings.BeforeCallAsync
?
Is't possible to use direct a JSON string and use this lib like a HTTP rest wrapper to CouchDB?
Expected:
CouchClient's IsUpAsync method returns false if connection can't be made / service is not up
Actual:
Uncaught CouchException is thrown
Tried to check whether valid CouchClient connection is up and running by using IsUpAsync method, but received uncaught CouchException instead when invalid IP/port was specified. I would expect it to return false when connection can't be established.
I did check from source code that RequestsHelper's SendRequestAsync method throws CouchNotFoundException only if HTTP 404 status is returned. However. If service is not up it might return other status codes or not respond at all.
In IsUpAsync method it's only catching CouchNotFoundException exception which may be too specific. Should it catch CouchException instead to cover up these other cases, or is there something else that could be done?
As a workaround I am currently catching this exception my self.
Currentlly we can create user, its works fine.
How i can update the password? Its not documented or not implemented yet?
It appears that the CouchDatabase database name is the name of the CouchDocument class and, thus, one can only have one CouchDocument class per database. If this is correct, I propose the addition of a means to associate multiple document models with a specific database. Perhaps an over name in AddCouchContext or an attributes.
Thank you! CoachDB.Net is great. Well done.
The link to the Source code on Nuget is invalid.
https://www.nuget.org/packages/CouchDB.NET
https://github.com/matteobortolazzo/couchdb-ne
Should be
https://github.com/matteobortolazzo/couchdb-net
After updating from 1.2.1 to latest 2.0.2 version conditions from variables stopped working. This same issue seems to happen in 2.0 version also.
I am able to call the Where method with variables in expressions without exceptions, but it returns with invalid results.
I would expect it to return the documents that matches with variables values, but it returns 0 documents instead. This worked like I would expect in earlier 1.2.1 version.
Running condition with constants in 2.0 / 2.0.2 version works as expected; it returns the documents that match with given condition.
It seems that the Where clause generates proper mango query that works as expected when run from CouchDb web administrative control panel. The same mango query doesn't get sent with CouchClient although. It is sending parameter name instead of its value
CouchDB testdb database document:
{
"id":"someid",
"property1" : "a"
}
Not working C# POC Code:
var database = GetDatabase<TestDocument>("testdb");
var variable1 = "a";
var mangoQuery = database.Where(d => d.Property1 == variable1);
var documentResults = mangoQuery.ToList();
Working C# POC Code:
var database = GetDatabase<TestDocument>("testdb");
var mangoQuery = database.Where(d => d.Property1 == "a");
var documentResults = mangoQuery.ToList();
Where clause generated mango query:
"selector": {
"$and": [
{
"property1": "a"
}
]
}
Actual what is being sent (checked from OnBeforeCallAsync httpCall param):
"selector": {
"$and": [
{
"property1": "variable1"
}
]
}
Expected:
"selector": {
"$and": [
{
"property1": "a"
}
]
}
EDIT1:
Checked that the call on
OnBeforeCallAsync
doesn't match the generated mango query. Seems that my example was little different. I'll update this soon
EDIT2:
Seems it was not about multi query after all. Updated the question, apologies for not noticing this earlier.
EDIT3:
Updated question + title
Adding or Updating a Document should either add or update a document, without throwing a "conflict" exception
public async Task<TReadModel> AddOrUpdateAsync(TReadModel entity)
{
var newdoc = CreateCDoc(entity);
var doc = CreateCDoc(entity);
try
{
doc = await Db.AddOrUpdateAsync(newdoc);
}
catch (Exception e)
{
_logger?.Fatal( JsonConvert.SerializeObject(e.ToXeption()));
doc = await Db.FindAsync(entity.Id);
if (doc == null)
{
doc = await Db.AddAsync(newdoc);
}
else
{
await Db.RemoveAsync(doc);
doc = await Db.AddAsync(newdoc);
}
}
return doc.Data;
}
{"Subject":"Unexpected Error","Content":"conflict","Msg":null,"Stack":" at CouchDB.Driver.Helpers.RequestsHelper.SendRequestAsync[TResult](Task`1 asyncRequest)\n at CouchDB.Driver.CouchDatabase`1.AddOrUpdateAsync(TSource document, Boolean batch, CancellationToken cancellationToken)\n at M5x.Store.CouchStore`1.AddOrUpdateAsync(TReadModel entity) in /home/rl/work/macula.io/netcore/m5x-sdk/src/M5x.Store/CouchStore.cs:line 70","Source":"CouchDB.NET","StatusCode":0,"Server":null,"ProtocolVersion":null,"Method":null,"LastModified":"2020-10-25T20:57:27.9994507Z","StatusDescription":null,"ErrorMessage":"conflict","ResponseStatus":null,"InnerXeption":{"Subject":"Unexpected Error","Content":"Call failed with status code 409 (Conflict): PUT http://toor:dev@localhost:5984/parksim-game/88609cbb122e4cfc9e476373520ce1c7","Msg":null,"Stack":" at Flurl.Http.FlurlRequest.HandleExceptionAsync(HttpCall call, Exception ex, CancellationToken token)\n at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)\n at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)\n at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T](Task`1 response)\n at CouchDB.Driver.Helpers.RequestsHelper.SendRequestAsync[TResult](Task`1 asyncRequest)","Source":"Flurl.Http","StatusCode":0,"Server":null,"ProtocolVersion":null,"Method":null,"LastModified":"2020-10-25T20:57:28.0113833Z","StatusDescription":null,"ErrorMessage":"Call failed with status code 409 (Conflict): PUT http://toor:dev@localhost:5984/parksim-game/88609cbb122e4cfc9e476373520ce1c7","ResponseStatus":null,"InnerXeption":null}
Which is a client side compatibile db under .NET ( Xamarin ) and that support sync?
purge_seq is string not int in CouchDB/3.1.0
CouchDB.Driver.Exceptions.CouchException : Exception of type 'CouchDB.Driver.Exceptions.CouchException' was thrown. ---- Flurl.Http.FlurlParsingException : Response could not be deserialized to JSON: GET http://localhost:5984/xunit-complete -------- Newtonsoft.Json.JsonReaderException : Could not convert string to integer: 0-g1AAAABPeJzLYWBgYMpgTmHgzcvPy09JdcjLz8gvLskBCeexAEmGBiD1HwiyEhlwqEtkSKqHKMgCAIT2GV4. Path 'purge_seq', line 1, position 127. at CouchDB.Driver.Helpers.RequestsHelper.SendRequestAsync[T](Task
1 asyncRequest)
at CouchDB.Driver.CouchDatabase1.GetInfoAsync() at LogetherFleet.CouchDb.Tests.CockpitOrderServiceTests.CountTest() in C:\_aaaaaa\logether-fleet\src\backend\CouchDbTests\CockpitOrderServiceTests.cs:line 131 --- End of stack trace from previous location where exception was thrown --- ----- Inner Stack Trace ----- at Flurl.Http.FlurlRequest.HandleExceptionAsync(HttpCall call, Exception ex, CancellationToken token) at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T](Task
1 response)
at CouchDB.Driver.Helpers.RequestsHelper.SendRequestAsync[T](Task1 asyncRequest) ----- Inner Stack Trace ----- at Newtonsoft.Json.JsonReader.ReadInt32String(String s) at Newtonsoft.Json.JsonTextReader.FinishReadQuotedNumber(ReadType readType) at Newtonsoft.Json.JsonTextReader.ReadAsInt32() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader) at Flurl.Http.Configuration.NewtonsoftJsonSerializer.Deserialize[T](Stream stream) at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T](Task
1 response)`
`GET http://localhost:5984/xunit-complete
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 444
Content-Type: application/json
Date: Thu, 02 Jul 2020 09:14:12 GMT
Server: CouchDB/3.1.0 (Erlang OTP/20)
X-Couch-Request-ID: a1581a3ed2
X-CouchDB-Body-Time: 0
{
"db_name": "xunit-complete",
"purge_seq": "0-g1AAAABPeJzLYWBgYMpgTmHgzcvPy09JdcjLz8gvLskBCeexAEmGBiD1HwiyEhlwqEtkSKqHKMgCAIT2GV4",
"update_seq": "78-g1AAAABPeJzLYWBgYMpgTmHgzcvPy09JdcjLz8gvLskBCeexAEmGBiD1HwiyErVwqEtkSKoHK1DJAgCK_Bms",
"sizes": {
"file": 536986,
"external": 264719,
"active": 227487
},
"props": {},
"doc_del_count": 0,
"doc_count": 50,
"disk_format_version": 8,
"compact_running": false,
"cluster": {
"q": 2,
"n": 1,
"w": 1,
"r": 1
},
"instance_start_time": "0"
}`
Is there an example of feed changes plus reactive elementsxin c# .net core?
`public async Task<IEnumerable<Voyage>> SetEmailSent(IEnumerable<Voyage> voyages)
{
if (voyages == null || !voyages.Any())
return null;
using (var couchClient = new CouchClient(couchDbUrl, g => g.EnsureDatabaseExists()))
{
var voyageMaster = couchClient.GetDatabase<Voyage>("test");
foreach (var voyage in voyages)
{
voyage.isEmailed = true;
}
return await voyageMaster.CreateOrUpdateRangeAsync(voyages);
}
}`
I'm getting an couchdb conflict response.
I'm reading from a db which have two records which have created on same time stamp. i believe when getting the data i should include IncludeConflicts()
but making it throw a Sequence contains no element error
I have these issue on 1.1.4 and i have updated 1.2.0.0 still the issue persis.
Let me know how this can be fixed.
Exception
Document update conflict.
Stacktrace
at CouchDB.Driver.Extensions.CouchDocumentExtensions.ProcessSaveResponse(CouchDocument item, DocumentSaveResponse response)
at CouchDB.Driver.CouchDatabase`1.<CreateOrUpdateRangeAsync>d__39.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
I have recently added index to the db is this reason for throwing this exception
I'm new to couchDb, so I'm not sure what I should look out for... does this nuget package support CouchDb v3 and up?
There are useful for storing synchronization metadata. For instance, when you synchronize CouchDB with other databases.
Documentation: https://docs.couchdb.org/en/3.1.0/api/local.html
FindAsync
currently catches CouchNotFoundException
so it returns null
in case that document is not found. I have mocked an implementation that is not using catch: n9@a877807. In case you would like me to pull-request it, let me know.
GetDatabase
with CheckDatabaseExists
setting can create database, if it does not exist. However, it is done synchronously (via AsyncContext.Run
). What about to provide another method ObtainDatabaseAsync
?
GetDatabasesNamesAsync
is called to check whether database exists. What about to use HEAD /db, which is more lightweight? (Moreover, what about to provide that functionality in function DatabaseExistsAsync
?)
It seems to me that in case that database does not exist, its name is escaped twice: first in GetDatabase
and then again in CreateDatabaseAsync
.
Hi @borigas
if you have free time, can you help me with the SSL cert?
It's something I'm not familiar with so I don't know what to copy and how to test it.
Thank you :)
[Fact]
public void Array_InEnum()
{
var json = _rebels.Where(r => r.Species.In(new[] { Species.Human, Species.Droid })).ToString();
Assert.Equal(@"{""selector"":{""species"":{""$in"":[0,1]}}}", json);
}
fails. It gives {"selector":{"species":{"$in":[Human,Droid]}}}
, which doesn't match other tests (Find_Selector.Enum()
) that are expecting enums to be serialized to ints
It looks like here and on line 45, the http content may be disposed before the async method completes, resulting in no http content being added to the request.
Are you planning to implement replication and update events? I am interested in using it.
I must admit being a newbie for CouchDB. While trying to use where predicates with query APIs, an exception is thrown indicating no Index found for the KeySpace... In this regard, I have below questions -
FindManyAsync
crashes when passing non-existent document id.
NullReferenceException: Object reference not set to an instance of an object.
at CouchDB.Driver.CouchDatabase`1.InitAttachments(TSource document)
at CouchDB.Driver.CouchDatabase`1.FindManyAsync(IEnumerable`1 docIds)
Making CouchClient.NewRequest
public would easily allow creating custom requests. (It might not be available on ICouchClient
interface.)
i'm trying to query all documents from services database
await using(var db = new DatabaseContext())
{
var services = await db.Services.ToListAsync();
.
.
.
}
the services database has 29 documents
but the statement returns only 25 records, exactly the first 25 records, and the last 4 are ignored, i've tried to add 1 more record, and the same happened, the first 25 records are returned and 5 got ignored.
is there any configuration to get all data??
@borigas
Any idea on how to get ExecutionStats and Bookmark?
The current implementation doesn't guarantee that the "Last" is really the last if async is involved.
Other than that and NewIndex, there should be all the previous features.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.