contexture-mongo
Mongo Provider for Contexture
Last updated 8 days ago by sp-dev .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install contexture-mongo 
SYNC missed versions from official npm registry.

contexture-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')
let provider = require('contexture-mongo')
let types = require('contexture-mongo/types')
let schemas = require('./path/to/schemas')

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

Default Types

Requiring contexture-mongo/types and calling it as a function will allow you to use a curated set of types we offer by default. contexture-mongo/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.

Current Tags

  • 0.17.0                                ...           latest (8 days ago)

56 Versions

  • 0.17.0                                ...           8 days ago
  • 0.16.0                                ...           12 days ago
  • 0.15.0                                ...           a month ago
  • 0.14.2                                ...           a month ago
  • 0.14.1                                ...           a month ago
  • 0.13.1                                ...           2 months ago
  • 0.13.0                                ...           2 months ago
  • 0.12.0                                ...           2 months ago
  • 0.11.3                                ...           2 months ago
  • 0.11.2                                ...           3 months ago
  • 0.11.1                                ...           3 months ago
  • 0.11.0                                ...           3 months ago
  • 0.10.1                                ...           3 months ago
  • 0.10.0                                ...           3 months ago
  • 0.9.5                                ...           7 months ago
  • 0.9.4                                ...           7 months ago
  • 0.9.3                                ...           8 months ago
  • 0.9.2                                ...           8 months ago
  • 0.9.1                                ...           8 months ago
  • 0.9.0                                ...           8 months ago
  • 0.8.5                                ...           a year ago
  • 0.8.4                                ...           a year ago
  • 0.8.3                                ...           a year ago
  • 0.8.2                                ...           a year ago
  • 0.8.1                                ...           a year ago
  • 0.8.0                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           2 years ago
  • 0.6.3                                ...           2 years ago
  • 0.6.2                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.6                                ...           2 years ago
  • 0.1.5                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.8                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 53
Last Day 0
Last Week 21
Last Month 63
Dependencies (7)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |