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

coral-mongo-tasks

v1.0.1

Published

Module wraps a few functions from 'mongodb' module inside Tasks (from folktale/data.task), for easy function composition (using, for example, Ramda's composeK).

Downloads

10

Readme

coral-mongo-tasks

coral-mongo-tasks is a library that simply takes a few of the most used functions from the mongodb module and wraps them inside the Task monad (from folktale/data.task). It also curries the functions and optimizes the order of their arguments.

The main aim is to allow for code reuse (or new function creation) via currying and to facilitate the composition of other functions which would make use of the ones provided by this library (using, for example, Ramda's composeK).

This is a low level module. For a higher level functionality you may want to check out coral-mongo-cruds and coral-mongo-attachments.

If you do not know anything about Tasks, you should know that they are like Promises but lazy. This links might help you understand them better.

Folktale's Data.Task documentation: http://folktalegithubio.readthedocs.io/en/latest/api/data/task/

Tasks Tutorial by Brian Lonsdorf: https://egghead.io/lessons/javascript-using-task-for-asynchronous-actions

Please note that this is just a thin wrapper, so it is better if you already know a bit about the mongodb module API.

Installation

npm install coral-mongo-tasks -S

Running tests

You should have mongodb installed globally. On one terminal window start Mongo Db: mongod

On another window: npm run test

If you want to watch the tests in order to make changes or play around: gulp

Sample Usage

const {findIn} = require('../mongo-tasks');
const {db} = require('./my-db-location');

//to get all documents from MyCollection
findIn(db, 'MyCollection', {}).fork(
	error => {
		//do something in case of error
	},
	results => {
		//do something in case of success
	}
);

API

This section is a work in progress. At the moment not all functions are described here. If you do not find what you need, it is recommended that you take a look at the source (and at the tests for usage).

connectDb :: DBUrl -> Database

connectDb(`mongodb://localhost:27017/mydatabase`).fork(
	error => {
		//do something in case of error
	},
	db => {
		//do something in case of success
	}
);

findIn :: Database -> CollectionName -> Query -> Task Error DbFind

findIn(db, 'MyCollection', {}).fork(
	error => {
		//do something in case of error
	},
	results => {
		//do something in case of success
	}
);

insertOne :: Database -> CollectionName -> Document -> Task Error DbWrite

insertOne(db, 'Users', {user:'someone'}).fork(
	error => {
		//do something in case of error
	},
	mongo_results_obj => {
		//do something in case of success
	}
);

insertMany :: Database -> CollectionName -> [Document] -> Task Error DbWrite

insertMany(db, 'Users', [{user:'someone'}, {user:'someone else'}]).fork(
	error => {
		//do something in case of error
	},
	mongo_results_obj => {
		//do something in case of success
	}
);

updateOne :: Database -> CollectionName -> UpdateParams -> Query -> Document -> Task Error DBWrite

updateOne(db, 'updateCollection', {upsert: false}, {user: 'someone'}, {user: 'someone', nickname: 'Pepito'}).fork(
	error => {
		//do something in case of error
	},
	mongo_results_obj => {
		//do something in case of success
	}
);

deleteInOne :: Database -> CollectionName -> Query -> Task Error DBWrite

deleteInOne(db, 'Users', {user: 'someone'}).fork(
	error => {
		//do something in case of error
	},
	mongo_results_obj => {
		//do something in case of success
	}
);