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

@contexture/provider-mongo

v0.27.0

Published

Mongo Provider for Contexture

Downloads

2

Readme

@contexture/provider-mongo

Mongo Provider for Contexture

Overview

This library assumes you'll pass a native Mongo client. For example, if you're using the package mongo, you would be passing the database object you get right after calling connect. Most of other MongoDB clients and similar tools provide a way to access the native client.

Usage

This provider takes a config object as a parameter, and expects a getClient method to be provided, which should return an instantiated MongoDB client.

| Option | Type | Description | Required | | ----------- | ---------- | ----------------------------------------------- | -------- | | getClient | function | Returns an instantiated MongoDB client | x | | types | object | Contexture node types, like all other providers | |

Schemas

Schemas using this mongo provider must specify a collection property, which is the name of the collection it runs against.

| Option | Type | Description | Required | | ------------ | -------- | ----------------------------------------------------------- | -------- | | collection | string | The MongoDB collection that will be used to run the queries | x |

Example Schema for SomeMongoCollection

module.exports = {
  mongo: {
    collection: 'SomeMongoCollection',
  },
}

Seting up contexture

let Contexture = require('@contexture/core')
let provider = require('@contexture/provider-mongo')
let types = require('@contexture/provider-mongo/dist/types')
let schemas = require('./path/to/schemas')

let process = Contexture({
  schemas,
  providers: {
    mongo: provider({
      getClient: () => client,
      types: types(),
    }),
  },
})

Default Types

Requiring @contexture/mongo/dist/types and calling it as a function will allow you to use a curated set of types we offer by default. @contexture/provider-mongo/dist/types allows you to pass a customization object that will allow you to pass custom parameters to the provided types.

mongoId

mongoId is filter only and compares against a mongo id, which in mongoose needs to be cast.

text

text is filter only and supports an array of values, a join, and an operator which it uses to construct a $regex filter.

The following operators are supported:

| Operator | Description | | ---------------- | ------------------------------------ | | containsWord | /WORD/ (matches mid-word) | | containsExact | /\bWORD\b/ (matches word in field) | | startsWith | /^WORD/ | | endsWith | /WORD$/ | | is | /^WORD$/ (exact match) | | wordStartsWith | /\bWORD/ | | wordEndsWith | /WORD\b/ |

date

date is filter only and converts {from, to} to a {$gte, $lte} mongo date filter. It also supports dateMath via @elastic/datemath (the same as supported by elasticsearch) to provide time ranges as well as three custom strings lastQuarter, thisQuarter, and nextQuarter (which are calculated on the fly). If you have dates that aren't store as dates, you can use dateType to change how the dates are output. The default is date, but you can also set it to unix for seconds from epoch or timestamp for a timestamp with milliseconds.

number

exists

facet

results

statistical

statistical will produce a list of statistical values in the context of the node. It does this by running count: { $sum: 1 }, $max, $min, $avg and $sum after running other available filters.

termsStats

termsStats is like statistical, grouped by the keyField

dateHistogram

Aggregates values for a field and groups into time periods specified by interval. Implements the statistical values listed above plus a cardinality count of unique values within each interval (the use case for this is when value_field isn't numeric).

Integration Tests

This repository offers integration tests to practice and understand the example types we offer. You can run the integration tests with the command: npm run test-integration. If you have a mongo database available at localhost (default port), the tests will connect to it and do changes on a database named contexture-test.