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

reactive-mongodb

v0.1.4

Published

An ODM for MongoDB with very strict data types/stucture. It is Based on Observable (with RxJS)

Downloads

1

Readme

Reactive-MongoDB

Reactive-MongoDB is An ODM for MongoDB with very strict data types/stucture. It is Based on Observable (with RxJS).

Why Observables

You can read about all the benefits of the Reactive approach (Reactive Architectures) here : RxJS5

Use RxJS's Operators you can work easily on your mongodb documents and define complexe behaviors in an easy to reason about way.

What's New

Currently working on data models so you can specifie the structure of your JSON objects and validate them before inserting them into your database. I made a module hyvalidator specificly for data validation, I plan on using it for this module to validate the data models.

Suggestions

Always Open For Suggestions. you can leave them as Issues

Bugs

Please report your bugs here: Issues

Installation

Add the project to your dependencies

npm install --save reactive-mongodb

To properly setup you need to connect to your mongo database with the following commands:

const connect = require('reactive-mongodb').connect;

connect('YOUR_DATABASE_URL');

You only need to do this once.

Collections

Reactive-MongoDB allows you to interact with your collections after you connect to your database.

New Collection

const Collection = require('reactive-mongodb').Collection;
//Collection is a class that represents your collection in the database
const Users = new Collection('users');
// 'users' will be the name of the collection in the mongodb database

Insert A Document

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

var user; //A document you want to insert

function onItemReceived(item) {
    // item is the document you inserted into the database
    // Your Own Logic
}

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.insert(user).subscribe(onItemReceived, errorHandler, completionHandler);

Update A Document

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

var oldUser; //A document you want to update
var newUser; //A document you want to update

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.updateOne(oldUser,newUser).subscribe(null, errorHandler, completionHandler);

Update will replace the oldUser by the newOne. If you want to update specifique field you have to use {$set:{fields:values}} instead of newUser:

Users.updateOne(oldUser,{$set:{fields:values}}).subscribe(null, errorHandler, completionHandler);

Update A Document By It's Id

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

var newUser; // The New Document

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.updateById(id,newUser).subscribe(null, errorHandler, completionHandler);
// You can also use $set instead of new User, See note Above

Update Multiple Documents

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

var query; //A query to determine which documents to update

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.update(query,{$set:{fields:values}}).subscribe(null, errorHandler, completionHandler);
// You have to specifie which fields to update with $set

Delete Multiple Documents

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

var query; //A query to determine which documents to delete

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.delete(query).subscribe(null, errorHandler, completionHandler);

Delete A Documents By Id

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.deleteById(id).subscribe(null, errorHandler, completionHandler);

The Id is the MongoDB ObjectID, you just need to pass in the String value Example :

Users.deleteById("590db2cc375bcc2cddc450a5").subscribe(onItemReceived, errorHandler, completionHandler);

Finding Documents

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

const query = {
    //Some Values
};

function onItemReceived(item) {
    // item is one of element of the array of documents that match the query
    // Your Own Logic
}

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.find(query).subscribe(onItemReceived, errorHandler, completionHandler);
// find will always return an array

Finding A Document

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');

const query = {
    //Some Values
};

function onItemReceived(item) {
    // item is one of element of the array of documents that match the query
}

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.findOne(query).subscribe(onItemReceived, errorHandler, completionHandler);
// find will return the first document Encoutered

Finding A Document By Id

const Collection = require('reactive-mongodb').Collection;
const Users = new Collection('users');


function onItemReceived(item) {
    // item is one of element of the array of documents that match the query
    // Your Own Logic
}

function errorHandler(err) {
    // err is the error thrown by the method
    // Your Own Logic
}

function completionHandler() {
    // Your Own Logic
}

Users.findById(id).subscribe(onItemReceived, errorHandler, completionHandler);
// Id is the string value of Object ID Of MongoDB, see delete by Id Example.

About the Author

I'm Khaled Romdhane but mostly known as heiyuki. My handle is : @heiyukidev.

I Work at this amazing Company @redcarpetsolutions don't hesitate to go check us out.

This project is backed By redcarpetsolutions