1

I'm trying to query a CouchDB database from Python and it works... but not entirely.

So, I created a partitioned DB with partition for movies, ratings, and tags and every partition _id is "partitionName : id".

Now I want to count the documents into ratings partition (100836 in the .csv file that I've downloaded)

After connection I do this:

mango1 = {"selector" : { "_id" : {"$regex" : "^ratings :"}}}
i = 0
for row in db.find(mango1):
    i += 1
print ("Ratings are: ", i)

It prints always 25, but from GUI I know that are more than 25 docs. How can I fix this problem? I read that Mango isn't able to count like SQL.

Joshua Beckers
  • 857
  • 1
  • 11
  • 24

1 Answers1

1

You get always 25 because the default CoucheDB limit is 25 documents.

You need to increase either

  • the Limit size so that all documents are retrieved in one go or
  • do some kind of pagination where you retrieve 25 documents each by using a start offset

Increase Limit of retrieved documents

To get for example 100 documents you could try this:

{"selector" : { "_id" : {"$regex" : "^ratings :"}}, "limit": 100}

Pagination A form of pagination could look like this:

{"selector" : { "_id" : {"$regex" : "^ratings :"}}, "limit": 50, "skip": 100}

This query will skip the first 100 documents and get you the following 50.

Joshua Beckers
  • 857
  • 1
  • 11
  • 24
  • Thank you, skip function seems not to work, but I have set the limit to 5 miollion and it works great –  Apr 28 '20 at 15:31
  • 1
    It's weird that it does not work, you should figure out what the problem is because it will be helpful for you in the future to use it. More information about how to use limit and skip can be found in the documentation: https://docs.couchdb.org/en/2.2.0/api/database/find.html – Joshua Beckers Apr 28 '20 at 15:35
  • I will find out because all this is fascinating me and I believe that NoSQL will be very useful in the future –  Apr 28 '20 at 15:40