{"id":15696957,"url":"https://github.com/pmlopes/p-odm","last_synced_at":"2025-05-08T23:27:04.414Z","repository":{"id":1986507,"uuid":"2918588","full_name":"pmlopes/p-odm","owner":"pmlopes","description":"Plugable ODM for Node.JS","archived":false,"fork":false,"pushed_at":"2013-03-18T18:55:13.000Z","size":413,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-22T18:54:26.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmlopes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-12-05T17:50:24.000Z","updated_at":"2015-01-15T09:34:03.000Z","dependencies_parsed_at":"2022-08-25T21:11:52.493Z","dependency_job_id":null,"html_url":"https://github.com/pmlopes/p-odm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fp-odm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fp-odm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fp-odm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fp-odm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmlopes","download_url":"https://codeload.github.com/pmlopes/p-odm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253162254,"owners_count":21863876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T19:10:32.936Z","updated_at":"2025-05-08T23:27:04.378Z","avatar_url":"https://github.com/pmlopes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ODM\n\nODM is a new, innovative and easy way to use MongoDB documents, as Models, in your code.\nIt uses the [JSON schema](http://tools.ietf.org/html/draft-zyp-json-schema-03) standard for validating the documents.\n\n## Quick Start\n\n### Connect\n\n\todm.connect('mongodb://127.0.0.1:27017/simple');\n\n### Define a model\n\n\tvar Person = odm.model(\"persons\", {\n\t  \"type\" : \"object\",\n\t  \"properties\": {\n\t    \"name\": {\"type\": \"string\"},\n\t  }\n\t});\n\n### Embedding other documents\n\nWe embed an address model in person:\n\t\n\t// Address, to be embedded on Person\n\tvar Address = odm.model({\n\t  \"id\": \"Simple#Address\",\n\t  \"type\" : \"object\",\n\t  \"properties\": {\n\t    \"lines\": {\n\t      \"type\": \"array\",\n\t      \"items\": {\"type\": \"string\"}\n\t    },\n\t    \"zip\": {\"type\": \"string\"},\n\t    \"city\": {\"type\": \"string\"},\n\t    \"country\": {\"type\": \"string\"}\n\t  }\n\t});\n\t\nThe changed person model:\n\t\n\tvar Person = odm.model(\"persons\", {\n\t  \"type\" : \"object\",\n\t  \"properties\": {\n\t    \"name\": {\"type\": \"string\"},\n\t    \"address\": {\"$ref\": \"Simple#Address\"}\n\t  }\n\t});\n\n\n## Methods\n\n### Class methods\n\n#### ODM#parse(jsonString)\nParses a JSON string to a JSON document. It is aware of ISO Dates and ObjectIds and coverts them on the fly.\n\n#### Model#findOne(query, fields, options, callback)\nFinds one document or `fields`, satisfying `query`.\n\n\tPerson.findOne({'name': 'Barack Obama'}, function (error, document) {\n\t  if (error) {\n\t    console.log(\"error\", error);\n\t  }\n\t  console.log(document);\n\t});\n#### Model#findById(id, fields, options, callback)\nFinds one document by `id`, returining `fields`.\n\n\tPerson.findById(\"4ff3fcf14335e9d6ba000001\", function (error, document) {\n\t  if (error) {\n\t    console.log(\"error\", error);\n\t  }\n\t  console.log(document);\n\t});\n#### Model#find(query, fields, options, callback)\nFinds all documents or `fields`, satisfying `query`.\n\n\tPerson.find({'name': 'Barack Obama'}, function (error, documents) {\n\t  if (error) {\n\t    console.log(\"error\", error);\n\t  }\n\t  console.log(documents);\n\t});\n\t\n#### Model#findAll(fields, options, callback)\nFinds all documents or `fields`.\n\n\tPerson.findAll(function (error, documents) {\n\t  if (error) {\n\t    console.log(\"error\", error);\n\t  }\n\t  console.log(documents);\n\t});\n\n#### Model#remove(query, options, callback)\nRemoves all documents satisfying `query`.\n\n#### Model#update(query, document, options, callback)\nUpdate all documents satisfying `query`, with document.\n\n#### Model#loadDbRef(id/ids, options, callback)\nLoads one Id or array of ids, it is similar to a simple find, however the number of results and order is the same as the array argument\n\n#### Model#ensureIndex(fieldOrSpec, options, callback)\nAdds an index and will also add a `findByXXX` method, where XXX is the name of the `fieldOrSpec`\n\n### Instance methods\n\n#### Model.validate(verbose)\nReturns true or false, or all errors in case `verbose` is true.\n\n#### Model.save(options, callback)\nSaves the instance model.\n\n\tp.save(function (error, id) {\n\t  if (error) {\n\t    console.log(\"error\", error);\n\t  } \n\t  console.log(id);\n\t});\n\n#### Model.update(query, document, options, callback)\nUpdate the instance model.\n\n#### Model.insert(options, callback)\nInsert the instance model.\n\n#### Model.remove(options, callback)\nRemove the instance model.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmlopes%2Fp-odm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmlopes%2Fp-odm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmlopes%2Fp-odm/lists"}