1. Home
  2. /
  3. N1ql
  4. /
  5. MongoDB Aggregation

MongoDB Aggregation - N1ql Typing CST Test

Loading…

MongoDB Aggregation — N1ql Code

Aggregation examples using MongoDB pipelines.

db.orders.aggregate([
	{ $match: { status: "completed" } },
	{ $group: { _id: "$customerId", total: { $sum: "$amount" } } },
	{ $sort: { total: -1 } }
])

N1ql Language Guide

N1QL (Non-First Normal Form Query Language) is Couchbase’s SQL-like query language designed for JSON document databases. It enables SQL-style querying, joins, aggregation, indexing, and full-text search on flexible JSON data.

Primary Use Cases

  • ▸SQL-style querying on JSON data
  • ▸JOIN operations on NoSQL JSON documents
  • ▸High-performance analytics
  • ▸Full-text search and indexing
  • ▸Caching and session management
  • ▸Recommendation engines and personalization pipelines

Notable Features

  • ▸Full SQL capabilities (SELECT, JOIN, GROUP BY, ORDER BY)
  • ▸Powerful secondary indexing
  • ▸Supports JSON-based schema flexibility
  • ▸User-defined functions and expressions
  • ▸Full-text search integration (FTS)
  • ▸High-performance distributed execution

Origin & Creator

Developed by Couchbase Inc., introduced publicly in 2015 to provide SQL querying capabilities on JSON in a distributed NoSQL database.

Industrial Note

N1QL excels in environments needing massive read/write throughput with SQL-like querying over JSON-such as ad-tech, gaming, finance, e-commerce personalization, digital catalogs, session stores, caching layers, and multi-model microservices.

More N1ql Typing Exercises

Basic N1QL QueriesBasic SQL JoinsPostgreSQL Window FunctionsRedis Sorted SetsCassandra Batch InsertNeo4j Path QuerySQLite IndexingElasticsearch Full-Text SearchInfluxDB Aggregation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlCypherGremlin