mongoql
Installation
This library is published in the NPM registry and can be installed using any compatible package manager.
npm install mongoql --save # For Yarn, use the command below. yarn add mongoql
Installation from CDN
This module has an UMD bundle available through JSDelivr and Unpkg CDNs.
<!-- For UNPKG use the code below. --> <!-- For JSDelivr use the code below. -->
Usage
; const UsersRelationships = address: 'address' MongoQL products: 'products' MongoQL ; const UsersQL = MongoQL
with relationships
const req = query: fields: 'name,address.zipcode,products.name' const pipeline = UsersQL "$lookup": "from": "addresses" "let": "value": "$_id" "pipeline": "$match": "$expr": "$eq": "$user" "$$value" "$project": "zipcode": 1 "as": "address" "$unwind": "path": "$address" "preserveNullAndEmptyArrays": true "$lookup": "from": "products" "let": "value": "$_id" "pipeline": "$match": "$expr": "$eq": "$user" "$$value" "$project": "name": 1 "as": "products" "$project": "name": 1 "address.zipcode": 1 "products.name": 1
without relationships
const req = query: fields: 'name' const pipeline = UsersQL "$project": "name": 1
with filters
const req = query: name: 'João' 'address.zipcode': '00000-000' fields: 'name,address.zipcode' const pipeline = UsersQL "$match": "name": "João" "$lookup": "from": "addresses" "let": "value": "$_id" "pipeline": "$match": "$expr": "$eq": "$user" "$$value" "$match": "zipcode": "00000-000" "$project": "zipcode": 1 "as": "address" "$unwind": "path": "$address" "preserveNullAndEmptyArrays": true "$project": "name": 1 "address.zipcode": 1
with helpers filters
const filtersFormatters = createdAt: MongoQLfiltersFormatters const UsersQL = MongoQL const req = query: name: 'João' createdAt: '2020-01-01,2020-01-10' fields: 'name,createdAt' const pipeline = UsersQL "$match": "name": "João" "createdAt": "$gte": "2020-01-01T00:00:00.000Z" "$lte": "2020-01-10T00:00:00.000Z" "$project": "name": 1 "createdAt": 1
Documentation
Documentation generated from source files by Typedoc.
License
Released under MIT License.