Code Monkey home page Code Monkey logo

couchdb-net's People

Contributors

adcorduneanu avatar alexandrshad avatar biapar avatar borigas avatar dhirensham avatar dmlarionov avatar matteobortolazzo avatar nefarius avatar panoukos41 avatar sacrilege avatar tjrobinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

couchdb-net's Issues

Documentation create index

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?

Custom serializer and multiple models

Hi!

I use couch db database with multiple models from F#, I was wondering:

  1. How to add work with a different serializer (because F# serialized bit weird)?
  2. How to work with different documents in the same db?

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");

ICouchDatabase.AddOrUpdate

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>.

IsMatch

IsMatch is moved to internal and cant be used
how is the like search now?

image

Version 1.2.2. this works
var result = db.Where(x => x.SearchText.IsMatch(match));

Camelized Member Names

@matteobortolazzo Why camelize the member names in

return jsonProperty != null ? jsonProperty.PropertyName : memberInfo.Name.Camelize();

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

Query Optimizer doesn't handle short circuited logical expressions

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.

Discriminator field can't be used

Hey, I was looking at the split feature instructions and noticed that the discriminator is set to be serialized as _discriminator but CouchDB will not allow that as shown in the picture below because _ character is considered special

image

IsUpAsync throws uncaught CouchException instead of returning success value

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.

Question, update user password

Currentlly we can create user, its works fine.
How i can update the password? Its not documented or not implemented yet?

One database with multiple document models?

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.

Unable to create queries from variables

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

AddOrUpdateAsync throws "conflict" exception

What I expect:

Adding or Updating a Document should either add or update a document, without throwing a "conflict" exception

The Code

  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;
        }

The Exception:

 {"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}

wrong type for purge_seq in CouchDatabaseInfo

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](Task1 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](Task1 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](Task1 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"
}`

Unable to update the document

  `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

FindAsync without catch

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.

EnsureDatabaseExists

  1. 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?

  2. 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?)

  3. 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.

$in queries with enums are serialized as names, not ints

[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

Replication & updates

Are you planning to implement replication and update events? I am interested in using it.

Query fails due to absence of Index

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 -

  1. How to create the index from the SDK? I couldn't find any related API in the SDK.
  2. Is it required to have a index created for each attribute that is required for filtering ?
  3. How does it work to know (and thereby fixing) the model schema upfront in a NoSql world? Aren't document / model supposed to be generic and not known upfront? What are the best practices here?

FindManyAsync crashes with NRE

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)

Expose CouchClient.NewRequest

Making CouchClient.NewRequest public would easily allow creating custom requests. (It might not be available on ICouchClient interface.)

Not getting all documents when using ToList/ToListAsync

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
services

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??

Replacing LastExecutionStats and LastBookmark.

@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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.