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

@zaeny/mongodb

v1.1.2

Published

Wrap mongodb node.js driver so it expose only two main function `query` and `transact`, so you can seperate pure function in domain business and side-effect (avoiding not dot notation call)

Downloads

8

Readme

@zaeny/mongodb

npm version npm downloads

Mongodb utility pure functions

Wrap mongodb node.js driver so it expose only two main function query and transact, so you can seperate pure function in domain business and side-effect (avoiding not dot notation call)

Getting started

npm i @zaeny/mongodb
// support module js 
var {query, find, transact, connectDb, createDb} = await import('@zaeny/mongodb);
import {query, find, transact, connectDb, createDb} from '@zaeny/mongodb; // individually
// support common js 
var {query} = require('@zaeny/mongodb');

Usage

process.env.MONGODB_URI="mongodb://mongouser:mongopass@localhost:27017/test?authSource=admin&tls=false";

var {createDb, connectDb, query, transact} = require('@zaeny/mongodb');

var clientDb = createDb(process.env.MONGODB_URI);
connectDb(clientDb)

var db => clientDb;

find({
  $db: "test",
  $coll: "tutorial",
  $where: {_id: 1}
}, db).then(console.log);

query([
  {$db: "test", $coll: "tutorial"},
  {$match: {}},
  {$project: {_id: 0, title: 1}},
  {$limit: 10}
], db).then(console.log);

query([
  {$db: "test", $coll: "tutorial"},
  {$group:{_id: null, total: {$sum: 1}}}
], db).then(console.log);

transact([
  {$db: "test", $coll: "tutorial"},
  {$create: {title: "why this is happen", description: "Just tutorial", published: false}}  
], db).then(console.log);

in the query the first query is always select database and collection by defining $db and $coll

{$db: "test", $coll: "tutorial"},

the rest of it is aggregate function to getting the data

...,
{$match: {_id: 1}},
{$sample:{size: 10}},
...

then we can implement onion architecture to seperate side-effect and the main core business

// core pure
var findUserByUsername = (username) => [
  {$db: 'my_db', $coll: 'story'},
  {$match:{ username }},
  {$limit: 1}
];

// controller api
await query(findUserByUsername(req.query.username), db);

inserting bulk, updating and deleting data with this api $create, $update, $updateMany, $delete, $deleteMany

example of usage transacting

...,
{$create: {title: "why this is happen", description: "Just tutorial", published: false}}
{$update: {
  $match: {title:/why/},
  $set: { updated_at: Date.now() }
}},
{$delete: {
  $match: {_id: 1}
}}

API

 createDb,
 connectDb,
 getDb,
 coll,
 find,
 query,
 find,
 transact

Related work

  • Composable - Collection of functions to solve programming problem

Changes

  • [1.0.0] add query and transact
  • [1.0.1] fix bugs transact allow operation default
  • [1.1.1] breaking changes transact now instead of $set $set it work on top operation
  • [1.1.2] fix homepage repository, add support import