Skip to content

Stream large collections #6

@erik-stephens

Description

@erik-stephens

Summary

As a developer of an API, I would like large collections streamed in chunks in order to minimize the memory footprint required to serve such requests.

Notes

Looks like Transfer-Encoding: chunked is already baked into express.js or node.js. However, looks like express.js is serializing json responses like this:

var body = JSON.stringify(obj, replacer, spaces);

Fortunately, looks like there is a stream-friendly mongoose api. Will just need to handle the serialization in crudify. JSONStream looks promising for that, but if not, can do it in crudify with something like this in sendResult.coffee:

res.send('[');
delim = '';
entity for entity in data
  res.send(delim + JSON.stringify(entity))
  delim = ','
res.send(']');

Tasks

  • Use the Mongoose.QueryStream API
  • Handle the serialization of ourselves instead of relying on express.js.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions