npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongodb-livedata-server

v0.1.2

Published

MongoDB live data server, extracted from Meteor, Fibers removed and converted to TypeScript

Downloads

13

Readme

MongoDB Live Data Server

This project is essentially a MongoDB live data driver (based either on polling or on Oplog tailing) combined with a DDP server, extracted out of Meteor, with Fibers and underscore dependencies removed and code converted to Typescript.

Live data is one of the root concepts of Meteor. Data is served via WebSockets via the DDP protocol and updated automatically whenever something changes in the database. Also, calling server methods via WebSocket is supported.

Using Meteor locks you into the Meteor ecosystem, which has some problems (mostly for historical reasons). Using live data as a separate npm package might be preferable in many scenarios. Also, people who are trying to migrate from Meteor, might find this package useful as an intermediate step.

Installation

npm i mongodb-livedata-server

Usage

As a most common example, this is how you can use livedata with Express.js:

const { DDPServer, LiveCursor, LiveMongoConnection } = require('mongodb-livedata-server')
const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

const httpServer = app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

const liveMongoConnection = new LiveMongoConnection(process.env.MONGO_URL, {
    oplogUrl: process.env.MONGO_OPLOG_URL
});
const liveDataServer = new DDPServer({}, httpServer);

liveDataServer.methods({
    "test-method": async (msg) => {
        console.log("Test msg: ", msg);
        return "hello! Current timestamp is: " + Date.now()
    }
})

liveDataServer.publish({
    "test-subscription": async () => {
        return new LiveCursor(liveMongoConnection, "test-collection", { category: "apples" });
    }
})

liveDataServer.methods and liveDataServer.publish have exactly same interface as Meteor.methods and Meteor.publish respectively, notice however that when publishing subscriptions, you must use LiveCursor rather than a normal MongoDB cursor.

Important notes

  • The project is in alpha. Use at your own risk.
  • Neither method context nor subscription context have the unblock method anymore (because this package doesn't use Fibers)
  • Meteor syntax for MongoDB queries is not supported. Please always use MongoDB Node.js driver syntax. For example, instead of
    const doc = myCollection.findOne(id);
    use
    const doc = await myCollection.findOne({ _id: id });
  • Neither MongoDB.ObjectId nor it's Meteor.js alternative is supported at the moment. String ids only.

DDP Extension

  • Starting from 0.1.0, this library extends DDP with init message, which is used to avoid initial spam of added messages.
  • Starting from 0.1.1, init message will only be sent if version 1a of DDP protocol is specified. Additionally, when version 1a is specified, server will not send removes for all documents when stopping a subscription, and rely on the client for the cleanup instead.