Collections
query.collection().fetch() is the SDK path for fetching every record that matches a query. It keeps requesting pages until the API has no next page, then returns a Nimbu.Collection.
With no filters, this means every record in the channel:
const allArticles = await new Nimbu.Query('articles')
.collection()
.fetch();With filters, it means every matching record:
const articles = await new Nimbu.Query('articles')
.equalTo('published', true)
.collection()
.fetch();Use this only when you really want the whole matching set in memory. For a list page, API response, export preview, or background job over a large channel, prefer one explicit page or batch iteration.
Collection Shape
Nimbu.Collection is a Backbone-style collection, not a plain array.
Access Records
articles.length;
articles.models;
articles.at(0);
articles.get(articleId);
articles.toJSON();Use .models when you need real array behavior:
for (const article of articles.models) {
console.log(article.get('title'));
}Iteration Helpers
Collections proxy many Underscore-style helpers to .models:
articles.forEach((article) => console.log(article.get('title')));
const titles = articles.map((article) => article.get('title'));
const drafts = articles.filter((article) => article.get('status') === 'draft');Common helpers:
| Method | Description |
|---|---|
forEach / each | Loop through models. |
map | Transform models. |
filter / select | Keep matching models. |
find / detect | Return first matching model. |
reduce | Build a value from models. |
some / every | Boolean checks. |
pluck | Read one attribute from every model. |
first / last | Get first or last model. |
isEmpty / size | Collection size helpers. |
Not Directly Iterable
Do not use collection instances directly with for...of, spread, or array destructuring.
for (const article of articles.models) {
// good
}
articles.forEach((article) => {
// also good
});Alternatives
Use batch iteration for large jobs:
await query.eachBatch(processBatch, { batchSize: 100 });Use find() for one page:
const page = await query.limit(50).skip(0).find();