{"id":43800,"library":"schm-mongo","title":"schm-mongo","description":"A composable schema extension for schm that parses query parameters into MongoDB queries, projections, and pagination. Version 0.4.1 is the latest stable release; the project appears to be in maintenance mode with no updates since 2018. It integrates with schm to define field projections via the `fields` parser, pagination via `page` with sort/limit/skip, geospatial queries via `near`, and operator-based filtering via `query`. Unlike monolithic ODM libraries, it provides lightweight, composable schema functions that work directly with the MongoDB Node.js driver or Mongoose.","status":"maintenance","version":"0.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/diegohaz/schm/tree/master/packages/schm-mongo","tags":["javascript","schm","schema","scheme","parser","validator","mongo","mongodb"],"install":[{"cmd":"npm install schm-mongo","lang":"bash","label":"npm"},{"cmd":"yarn add schm-mongo","lang":"bash","label":"yarn"},{"cmd":"pnpm add schm-mongo","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: provides the base schema parsing engine; schm-mongo requires schm ^0.4.0","package":"schm","optional":false}],"imports":[{"note":"Named export from the package root. CommonJS using require is also fine, but avoid deep imports.","wrong":"const { query } = require('schm-mongo/query')","symbol":"query","correct":"import { query } from 'schm-mongo'"},{"note":"Correctly imported as a named export. The wrong example is actually valid but less idiomatic in ES modules.","wrong":"const fields = require('schm-mongo').fields","symbol":"fields","correct":"import { fields } from 'schm-mongo'"},{"note":"Named export. No common mistake beyond ensuring you import from the correct package.","wrong":"","symbol":"page","correct":"import { page } from 'schm-mongo'"},{"note":"There is no default export; must use named import. Attempting default access is a common error.","wrong":"const near = require('schm-mongo').default.near","symbol":"near","correct":"import { near } from 'schm-mongo'"}],"quickstart":{"code":"const schema = require('schm');\nconst { query, fields, page } = require('schm-mongo');\n\nconst userSchema = schema({\n  name: String,\n  age: { type: Number, operator: '$gte' },\n});\n\nconst querySchema = schema(userSchema, query(), fields(), page());\n\nconst parsed = querySchema.parse({\n  name: 'Alice',\n  age: '18',\n  fields: ['name', 'age'],\n  limit: '10',\n  page: '2',\n});\n/* parsed:\n{\n  name: 'Alice',\n  age: { '$gte': 18 },\n  fields: { name: 1, age: 1 },\n  page: { limit: 10, skip: 10, sort: undefined }\n}\n*/\n\n// Use with mongodb driver\ndb.collection.find(parsed, parsed.fields)\n  .limit(parsed.page.limit)\n  .skip(parsed.page.skip);","lang":"javascript","description":"Demonstrates parsing query parameters, field projections, and pagination using schm-mongo with the schm schema library."},"warnings":[{"fix":"Consider alternatives like @hapi/joi with custom MongoDB transformers or mongoose for full ODM support.","message":"Package is no longer actively maintained. Last release 0.4.1 on 2018-03-05.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure schema fields that should become MongoDB operators have `operator` set, e.g., `{ type: Date, operator: '$gte' }`.","message":"The `query()` parser only wraps fields that have an explicit `operator` property in the schema definition. Without operator, values are passed as-is.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always specify fields to avoid unintended projection. Use `fields: ['-_id', 'name']` to hide `_id`.","message":"`fields()` defaults to including all fields if not specified. To exclude `_id`, you must explicitly pass `fields: ['-_id']`.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pass numeric strings like '1' and '10' as query params; the parser handles conversion.","message":"`page()` expects `page` and `limit` query parameters as strings and parses them to numbers. If values are missing, they default to page=1 and limit=10.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Supply coordinates as 'lat,lng' string. Remember GeoJSON order is [longitude, latitude].","message":"`near()` requires a geo field name. The input must be a comma-separated string of lat,lng coordinates, and the parsed output uses GeoJSON format `[lng, lat]` (note longitude first).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.4.1':21 '2018':39 'appear':29 'base':64 'compos':5,75 'defin':45 'direct':80 'driver':85 'extens':7 'field':46,50 'filter':65 'function':77 'geospati':57 'integr':41 'javascript':88 'latest':24 'librari':71 'lightweight':74 'mainten':33 'mode':34 'mongo':3,94 'mongodb':15,83,95 'mongoos':87 'monolith':69 'near':60 'node.js':84 'odm':70 'oper':63 'operator-bas':62 'page':54 'pagin':19,52 'paramet':13 'pars':11 'parser':51,92 'project':17,28,47 'provid':73 'queri':12,16,58,67 'releas':26 'schema':6,76,90 'scheme':91 'schm':2,9,43,89 'schm-mongo':1 'sinc':38 'sort/limit/skip':56 'stabl':25 'unlik':68 'updat':37 'valid':93 'version':20 'via':48,53,59,66 'work':79","created_at":"2026-06-05T17:01:32.509744+00:00","updated_at":"2026-06-05T17:01:32.509744+00:00","problems":[{"fix":"Run `npm install schm@^0.4.0` alongside schm-mongo.","cause":"Missing required peer dependency schm.","error":"Cannot find module 'schm'"},{"fix":"Use `const schema = require('schm')` (CommonJS) or `import schema from 'schm'` (ESM).","cause":"Incorrect import of schm; likely using `require('schm').default` in CJS or wrong import style.","error":"TypeError: schema is not a function"},{"fix":"Use `import { query } from 'schm-mongo'` or `const { query } = require('schm-mongo')`.","cause":"Named export not imported correctly; possibly import default instead of named.","error":"TypeError: (0 , _schmMongo.query) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/diegohaz/schm/tree/master/packages/schm-mongo","github":"https://github.com/diegohaz/schm/tree/master/packages/schm-mongo","docs":null,"changelog":null,"pypi":null,"npm":"schm-mongo","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}