Skip to content

Querying collections

Sails Content provides the sails-content adapter which makes querying your content collections with Waterline queries super easy.

Entries from a collection

Let's say you want to return all the entries in the blog collection we created earlier in getting started, you can use the .find() Waterline query method in your action:

module.exports = {
  fn: async function () {
    const blogPosts = await Blog.find({
      select: ['title', 'slug']
    return { blogPosts }


You can use the select and omit projections to specify what you want returned.

Notice we have a pages/blog template. We are passing blogPosts to it and then we can display the posts like this:

<!DOCTYPE html>
<html lang="en">
    <title>Blog | Hagfish</title>
      <h2>Stay up to date with the latest news and updates.</h2>
        <% blogPosts.forEach(post => { %>
          <h3><%= post.title %></h3>
          <a href="/blog/<%= post.slug %>">Read more</a>
        <% }) %>

A single entry from a collection.

You can also get a single entry from a collection using .findOne() Waterline query method in your action. You pass in the slug - file name - of the .md file:

module.exports = {
  fn: async function () {
    const post = await Blog.findOne('hello-world') 
    return { posts }

All open source projects are released under the MIT License.