/fireferret

Node.js Read-through cache for MongoDB 🔥🙈

Primary LanguageJavaScriptMIT LicenseMIT

Logo

FireFerret

Autocaching query client for MongoDB, with powerful filtering functionality.

We care about response times!

License: MIT JavaScript Style Guide: Standard Build Status Coverage Status

NPM

References

What? Where?
API-Documentation https://mster.github.io/fireferret/
Client Config https://mster.github.io/fireferret/Options.html#.FireFerretOptions
Source code https://github.com/mster/fireferret
MongoDB https://www.mongodb.com/
Redis https://redis.io/

Requirements

FireFerret requires MongoDB and Redis instances.

Usage

const FireFerret = require("fireferret");

const ferret = new FireFerret({
  mongo: { uri: "...", collectionName: "..." },
  redis: { host: "...", port: 6379, auth_pass: "..." },
});

await ferret.connect();
const docs = await ferret.fetch({ "some.field": /.*/ });

Query some documents using pagination.

const docs = await ferret.fetch(
  { genre: { $in: ["Djent", "Math Metal"] } },
  { pagination: { page: 3, size: 20 } }
);

FireFerret supports streaming queries.

await ferret.fetch({ isOpen: true }, { stream: true }).pipe(res);

Using the Wide-Match strategy.

const smartFerret = new FireFerret({
  /* ... ,*/
  wideMatch: true,
});
await smartFerret.connect();

const query = { candidates: { $ne: "Drumpf", $exists: true } };

/* cache miss */
const first50docs = await smartFerret.fetch(query, {
  pagination: { page: 1, size: 50 },
});

/* cache hit */
const first20docs = await smartFerret.fetch(query, {
  pagination: { page: 1, size: 20 },
});

/* cache hit */
const first10docs = await smartFerret.fetch(query, {
  pagination: { page: 1, size: 10 },
});

/* cache hit */
const firstDoc = await smartFerret.fetchOne(query);

Contributing

We welcome you with open arms. Contributions are appreciated after v1.0.0