Neil
Neil

Reputation: 332

ravendb python api, query always return 128

I'm querying my ravendb instance. My target collection contain more than 30k documents. I'm using pyravendb with python 3.

I'm querying my index using the following code :

result_ = self.store.database_commands.query(index_name="Raven/DocumentsByEntityName",
                                                    index_query=IndexQuery("Tag:MyCollection",total_size=128,skipped_results=start))
if len(result_['Results']) < 128:
     return

start being the offset variable that increments by 128 each time I query. When I run this code the result's length is always 128 which leads to an infinite loop.

Any ideas why it acts like this ?

Upvotes: 1

Views: 242

Answers (3)

Idan Haim Shalom
Idan Haim Shalom

Reputation: 1244

take a look here in my commit Get all of a collection's documents id's RavenDB for a "per-document" modification

In pyravendb v3.5.3.5 I updated the IndexQuery and now you able to skip or to take less or more documents then 128.

The other thing don't use total_size or skipped_results (They are going to be removed)

Upvotes: 1

Neil
Neil

Reputation: 332

The problem was the parameter I was using. The proper parameter that should be used is start = offset_that_you_want_to_skip and not skipped_results=offset.

the correct code is the following :

result_ = self.store.database_commands.query(index_name="Raven/DocumentsByEntityName",
                                                    index_query=IndexQuery("Tag:MyCollection",total_size=128,skipped_results=0, default_operator=None,start=offset)) 
#blablabla
offset+=128
if len(result_['Results']) < 128:
         return

Upvotes: 1

Omir
Omir

Reputation: 320

I know this is not exactly going to answer your question but did you consider using RavenDB's streaming functionality? https://ravendb.net/docs/article-page/3.5/csharp/client-api/session/querying/how-to-stream-query-results

In many cases when dealing with a large number of documents this might be faster and simpler compared to iterating with Query().

However please be aware that streamed objects will not be tracked. Meaning changes to these objects and a consequent SaveChanges()-call wont have any effect to the documents stored within RavenDB.

Upvotes: 0

Related Questions