Skip to content

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:

js
const allArticles = await new Nimbu.Query('articles')
  .collection()
  .fetch();

With filters, it means every matching record:

js
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

js
articles.length;
articles.models;
articles.at(0);
articles.get(articleId);
articles.toJSON();

Use .models when you need real array behavior:

js
for (const article of articles.models) {
  console.log(article.get('title'));
}

Iteration Helpers

Collections proxy many Underscore-style helpers to .models:

js
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:

MethodDescription
forEach / eachLoop through models.
mapTransform models.
filter / selectKeep matching models.
find / detectReturn first matching model.
reduceBuild a value from models.
some / everyBoolean checks.
pluckRead one attribute from every model.
first / lastGet first or last model.
isEmpty / sizeCollection size helpers.

Not Directly Iterable

Do not use collection instances directly with for...of, spread, or array destructuring.

js
for (const article of articles.models) {
  // good
}

articles.forEach((article) => {
  // also good
});

Alternatives

Use batch iteration for large jobs:

js
await query.eachBatch(processBatch, { batchSize: 100 });

Use find() for one page:

js
const page = await query.limit(50).skip(0).find();

Part of Nimbu, built by Zenjoy.