Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

danf-gnucki-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

danf-gnucki-mongodb

A danf module for mongoDB

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 05 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc