You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Loopback中设置查询的起始偏移量与数量限制?

How to Implement Offset + Limit Pagination in LoopBack for MySQL

Hey there! I see you're trying to replicate the MySQL query SELECT * FROM ace_new.customer_profile LIMIT 10,5 (skip the first 10 rows and fetch the next 5) in LoopBack, and you've already got the limit part working. Let me show you the missing piece here.

In LoopBack, to achieve the equivalent of MySQL's LIMIT offset, row_count syntax, you need to use two query options together:

  • limit: Specifies the number of rows to fetch (this is the second value in your MySQL LIMIT clause, which is 5 here)
  • offset: Specifies how many rows to skip before starting to fetch (this is the first value in your MySQL LIMIT clause, which is 10 here)

Here's the corrected code for your scenario:

weapons.find({
  order: 'id DESC',
  limit: 5,   // Fetch 5 rows
  offset: 10  // Skip the first 10 rows
});

When you run this query, LoopBack will generate the exact MySQL statement you're targeting: SELECT * FROM weapons ORDER BY id DESC LIMIT 10, 5 (assuming your model maps to the weapons table).

This combination of offset and limit is the standard way to implement pagination or offset-based fetching in LoopBack for relational databases like MySQL.

内容的提问来源于stack exchange,提问作者Ginto Joseph

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:42:14