Bypassing Wix Database 100 query limit for blog

Hey everyone. I’m currently trying to implement a next/previous button at the bottom of my post page. I am using this code from this tutorial: How to add Next/Previous buttons to your post (wix-blog-community.com)

import wixData from 'wix-data';
import wixLocation from 'wix-location';
 
let posts = [];
 
$w.onReady(function () {
   wixLocation.onChange((location) => {
       init();
   })
   init();
 
});
 
async function getPosts() {
   return wixData.query("Blog/Posts")
   .limit(100)
   .ascending("publishedDate")
   .find()
       .then((results) => {
           posts = results.items;
       })
}
 
function getCurrentPostIndex(url) {
   let index;
   posts.forEach((post, i) => {
       if (post.postPageUrl === url) {
           index = i;
       }
   });
   return index;
}
 
function init() {
   console.log('init');
   let currentPostUrl;
   let currentPostIndex;
 
   wixData.query("Blog/Posts")
   .limit(100)
   .ascending("publishedDate")
   .find()
       .then((results) => {
           posts = results.items;
       }).then(() => {
           currentPostUrl = `/${wixLocation.path.join('/')}`;
           currentPostIndex = getCurrentPostIndex(currentPostUrl) || 0;
 
           console.log(currentPostIndex);
 
           if (currentPostIndex === 0) {
               $w('#previousBox').hide();
           } else {
               $w('#previousBox').show();
               const prevPostTitle = posts[currentPostIndex - 1].title;
               $w('#previousPost').text = prevPostTitle;
           }
 
           if (currentPostIndex === posts.length) {
               $w('#nextBox').hide();
           } else {
               $w('#nextBox').show();
               const nextPostTitle = posts[(currentPostIndex || 0) + 1].title;
               $w('#nextPost').text = nextPostTitle;
           }
       })
 
   $w('#previous').onClick(() => {
       wixLocation.to(posts[currentPostIndex - 1].postPageUrl);
   });
   $w('#previousPost').onClick(() => {
       wixLocation.to(posts[currentPostIndex - 1].postPageUrl);
   });
   $w('#next').onClick(() => {
       wixLocation.to(posts[currentPostIndex + 1].postPageUrl);
   });
   $w('#nextPost').onClick(() => {
       wixLocation.to(posts[currentPostIndex + 1].postPageUrl);
   });
}

My issue is that I have more than 100 blog posts. I’m aware that creating my own collection can allow me a limit of 1000, but I don’t know how to implement it in this code. I’m a complete beginner at coding. Any help and guidance for a solution will be appreciated.

Your code is not exactly what the tutorial has. You added a limit to the query:

.limit(100)

You can try changing it to:

.limit(1000)

(1000 is the maximum limit allowed)

You might want to ask the author of the tutorial for further assistance.

Please understand that you can’t just “copy and paste” code and expect it to work. You need to understand what’s happening if you expect to be able to write code that does what you want. To learn about programming with Velo, read the following articles that will help you get started:

  • About Velo by Wix - what Velo is and what features it has.

  • Getting Started with Velo by Wix - step-by-step tutorial on how to start using Velo.

  • Onboarding to Velo by Wix - introduction to Velo with short tutorials.

  • Velo Examples - has many examples demonstrating a wide variety of features and techniques. Filter by “Beginner” to get started.

Hello, the limit query for Wix App Databases is at 100 . This is using Blogs by WIx. Putting a limit beyond 100 results in an error. I already tried that before. I followed the baseline of the code and added my own sort functions (Ascending by Publish Date) because I want my chapters to be in numerical order. Also, by default, the query loads 50 if undefined.

I obviously know I can’t “simply” copy and paste a code and expect it to work. In fact, this code works perfectly fine. As my title suggested, I want to see if anyone knows of a method to bypass the limit or if they can redirect me to sources relevant to the answers I’m searching for. I’ve already gone through the Velo basics and guides and would just like more tailored advice.

@tslaaaang
Hello everybody (hello Yisrael), nice to be here again, after a long time of absence.

Well, the described issue of Tee Slang, remembers me to a similar issue, i had once, when i was working with Wix-Stores.

Might be the post-opener is right, when he say that a max. limitation is set to 100.
I myself am not sure anymore if this is correct, since i already forgot few things (it’s long ago, when i was the last time here).

So, here you will finde the similar issue i am talking about…
https://www.wix.com/velo/forum/coding-with-velo/wix-stores-products-100-query-limit

I do not know where to find the info for the limitation of the Blog-DB, but i assume, it is also set to a max-limit of 100, the same way like in the DATABASE of Wix-Stores, where you can handle max. 100-items at once.

In this case using a PAGINATOR is perhaps a good idea, or generating NEXT and PREVIOUS - function, another possibility to handle the issue.

If it comes to LIMIT, then a SKIP is not far away. What does that mean?
Let’s say you have 1000-items in your DATABASE, but you only can load 100-first-items of 1000-total-items.

What you’ll need now, would be a NEXT-STEP-FUCTION, wich would load next 100-items and which would skip the first 100-items.

So we have already 2.-methods/functions involved…
1)

.limit();
.skip();

Here you will find another post, where i had a similar issue…

In this post you will find some not complete examples and no real END-SOLUTION (because this information was not for public due to a project i am still working on, called iQuery).

But at the end, i can tell you, that there is a solution for your problem.
Maybe regarding all the shown post, you will recognize what to do and how to solve your issue.

Also, take a look onto this post here…

…here you will find another very important method/function, which is very important, when it comes to work with several queries.

Promise.all()
return Promise.all([
    query('collection').limit(1000).find(),
    query('collection').limit(1000).skip(1000).find(),
    query('collection').limit(1000).skip(2000).find(),
    query('collection').limit(1000).skip(3000).find(),
]).then((res) => {
    const cache = { items: [] }
    for (const result of res) {
        cache.items = cache.items.concat(result.items);
    }
})

Try to combine all the informations out of the shown posts.

You will also find even more usefull stuff, related to your mentioned issue, just try to use the FORUM-SEARCH.

Type into the SEARCHBAR the following :arrow_right: 1000 and search for it.:wink:

@russian-dima Thank you so much for your detailed response! I will be sure to check out all the posts you linked! I tried search the forum myself too but most of them suggesting creating my own collection which I did, but I was struggling how to switch the databases and whatnot. I’ll dig deeper into the forums as you suggested.

I look forward to testing this all out. This is very helpful, have a great day!