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

danf-gnucki-mongodb

v0.1.3

Published

A danf module for mongoDB

Downloads

4

Readme

danf-gnucki-mongodb

Danf module for mongoDB

Use as a danf module

Add the module to your package.json:

npm install danf-gnucki-mongodb --save

Execute tests

$ make test

Use

Define connections

gnuckiMongodb: {
    // Define the list of connections.
    connections: {
        // Define a connection of name "forum" on the database "forum".
        forum: {
            // Define the mongodb connection URL and additional options.
            // (https://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html#the-url-connection-format)
            url: 'mongodb://localhost:27017/forum',
            options: {
                server: {
                    poolSize: 2
                }
            },
            // Define the collections in the database.
            collections: {
                // Define a collection of name "forums".
                forums: {
                    // Define a danf contract in order to validate inserted documents.
                    document: {
                        title: {
                            type: 'string',
                            required: true
                        }
                    }
                },
                topics: {
                    document: {
                        title: {
                            type: 'string',
                            required: true
                        },
                        forum: {
                            type: 'string|gnuckiMongodb:document.forum.forums',
                            required: true
                        },
                        views: {
                            type: 'number',
                            default: 0
                        }
                    },
                    // Define the collection indexes.
                    indexes: {
                        // Define an index of name "forum" on the key "forum"
                        // with some options.
                        forum: {
                            keys: {forum: 1},
                            options: {
                                background: true
                            }
                        }
                    }
                },
                // Define a simple collection without schema validation.
                posts: {}
            }
        },
        // Define a connection of name "user" on the database "users".
        user: {
            url: 'mongodb://127.0.0.1:27017/users',
            collections: {
                users: {
                    // Override the default collection name of "users"
                    // with "authors".
                    name: 'authors',
                    document: {
                        username: {
                            type: 'string',
                            required: true
                        },
                        password: {
                            type: 'string',
                            required: true
                        }
                    }
                },
                connections: {
                    document: {
                        ip: {
                            type: 'string',
                            required: true
                        },
                        date: {
                            type: 'date',
                            required: true
                        },
                        user: {
                            type: 'string|gnuckiMongodb:document.user.users',
                            required: true
                        }
                    },
                    // Define some options for the creation and fetching
                    // of the collection (used for capped collections for instance).
                    options: {
                        capped: true,
                        size: 1000000,
                        max: 1000,
                        w: 1
                    }
                }
            }
        }
    }
}

Request a collection

In a sequence:


// config/server/config/sequences.js

'use strict';

module.exports = {
    consultTopic: {
        stream: {
            topicId: {
                type: 'object|string',
                required: true
            }
        },
        operations: [
            // Find the topic.
            {
                order: 0,
                service: 'gnuckiMongodb:db.forum.collection.topics',
                method: 'findOne',
                arguments: [
                    {_id: '@topicId@'}
                ],
                scope: 'topic'
            },
            // Increase the views number of the topic simultaneously
            // (same orders = parallel execution).
            {
                order: 0,
                service: 'gnuckiMongodb:db.forum.collection.topics',
                method: 'updateOne',
                arguments: [
                    {_id: '@topicId@'},
                    {$inc: {views: 1}}
                ]
            },
            // Find the related forum after topic retrieving
            // (different orders = sequential execution).
            {
                order: 1,
                service: 'gnuckiMongodb:db.forum.collection.forums',
                method: 'findOne',
                arguments: [
                    {_id: '@topic.forum@'}
                ],
                scope: 'forum'
            }
        ]
    }
};

Take a look at the documentation of the native driver for a list of available methods.

Todo

  • create indexes
  • check document format: insert + update $set
  • override the default collection: 'gnuckiMongodb:db.forum.collection.topics': {parent: 'gnuckiMongodb:db.forum.collection.proxy', properties: { collection: '#gnuckiMongodb:db.forum.collection.topics.default#'}} // 'gnuckiMongodb:db.forum.collection.topics': {alias: gnuckiMongodb:db.forum.collection.topics.default}
  • type document: find cursor set __implement on objetcs of "free" interfaces
  • handle mongoId and references: custom dataResolver with a dataInterpreter decoding types "gnuckiMongodb.document.."
  • handle collection and db events
  • handle stream cursor
  • clean useless files and documentation
  • make tests
  • npm publish