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

mongo-fixtures

v1.0.1

Published

Populate MongoDB with dummy collections for testing

Downloads

4

Readme

mongo-fixtures

Populate MongoDB with dummy collections for testing

NPM version

Elevator pitch

mongo-fixtures will read JSON documents from disk, and use them to quickly populate a MongoDB database. You can use it to bootstrap a local environment, or to initialise data required for functional tests.

Data sets

The fake data is organised in "datasets", which represent a whole set of consistent data. They are just folders on disk, containing both files and folders:

  • Files will be loaded as an entire collection. They need to export an array of documents
  • Folders are expected to contain one file per document, each exporting a single object.

For example:

dataset1
   |___ users.coffee
   |___ history.coffee
   |___ products
            |___ phone.coffee
            |___ guitar.coffee   

Why coffee?

Maybe a personal preference, but it:

  • looks nicer than JSON
  • has better syntax highlighting
  • supports comments
  • can use actual data types without fishy post-processing
  • can use helpers & extracted methods
{
	# valid user without an address
    _id: ObjectID('fffffffffffffff000000001')
    name: 'John Doe'
    memberSince: new Date('28 Mar 2013')
}

Configuration

The config file has 2 main sections. (see the examples folder for an config file you can copy).

  • The data sets that can be loaded. These are just paths to a folder containing all the collections.
    datasets:
        bootstrap: "#{__dirname}/dataset1"
        functests: "#{__dirname}/dataset2"
  • The environments they can be loaded into. For each environment, you must specify which collections from the datasets will be loaded. For example, maybe you never want to load users into dev.
    envs:
        local:
            database: (user, pass) -> 'mongodb://localhost:27017/mystore'
            collections: ['users', 'products', 'history']
        dev:
            database: (user, pass) -> "mongodb://#{user}:#{password}@alex.mongohq.com:10023/mystore"
            collections: ['products']

Let's go

Just npm install mongo-fixtures!

Automated mode

Great for build scripts

fixtures = require 'mongo-fixtures'

options =
    dataset: 'bootstrap'
    env: 'local'
    username: null
    password: null

fixtures(config).load options, finish

Interactive mode

Will prompt you for all required values

fixtures = require 'mongo-fixtures'
fixtures(config).interactive finish

A sample callback would be:

finish = (err, res) ->
    if err
        console.log err
        process.exit 1
    else
        console.log res
        process.exit 0