{"id":19179278,"url":"https://github.com/royalgarter/mongoose-acrud","last_synced_at":"2025-06-30T06:04:28.235Z","repository":{"id":57301910,"uuid":"77601466","full_name":"royalgarter/mongoose-acrud","owner":"royalgarter","description":"mongoose-acrud","archived":false,"fork":false,"pushed_at":"2021-05-10T04:36:47.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T11:34:30.185Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/royalgarter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-29T09:40:38.000Z","updated_at":"2021-05-10T04:36:49.000Z","dependencies_parsed_at":"2022-08-24T17:12:37.560Z","dependency_job_id":null,"html_url":"https://github.com/royalgarter/mongoose-acrud","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/royalgarter/mongoose-acrud","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fmongoose-acrud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fmongoose-acrud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fmongoose-acrud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fmongoose-acrud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/royalgarter","download_url":"https://codeload.github.com/royalgarter/mongoose-acrud/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fmongoose-acrud/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260690826,"owners_count":23047098,"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-11-09T10:42:38.687Z","updated_at":"2025-06-30T06:04:28.200Z","avatar_url":"https://github.com/royalgarter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Install\n\n* npm i mongoose-acrud --save\n\n## Feature list\n\n * ACRUD (Aggregate, Create, Read, Update, Delete)\n * Build for usage with [ExpressJS](http://expressjs.com/)\n * Support populate \u0026 deep populate\n * Support APIKEY for database / model\n\n\n## Usage\n\n(with basic Mongoose)\n* Assume that folder that contain schema files is './schemas'\n\n```javascript\nconst acrud = require('mongoose-acrud');\nacrud.init({\n  mongoose: mongoose,\n  schemaFolder: path.join(__dirname, 'schemas')\n});\napp.post(acrud.ROUTE, acrud.controller);\n```\n\n(with [KeystoneJS](http://keystonejs.com/))\n* Assume that you setup \u0026 init keystone somewhere else\n\n```javascript\nconst keystone = require('keystone');\nconst acrud = require('mongoose-acrud');\nacrud.init({\n  keystone: keystone,\n  mongoose: keystone.get('mongoose'),\n});\napp.post(acrud.ROUTE, acrud.controller);\n```\n\nSee [Detail example with ExpressJS, Mongoose](https://github.com/royalgarter/mongoose-acrud/blob/master/test.js):\n\n## POST Authorization using Header\n\n```javascript\ncurl -X POST -H \"Authorization: \u003cYOUR_APIKEY\u003e\"\n```\n\nAuthorization level by Bitwise value on process.env\n\n* ACRUD: 11111 = 31\n* Aggr: 10000 = 16\n* Create: 01000 = 8\n* Read: 00100 = 4\n* Update: 00010 = 2\n* Delete: 00001 = 1\n\n### Example:\n\n* Set Enviroment: MY_SUPER_APIKEY=31 (mean this key is fullaccess to every action)\n\nQuery by cURL\n```javascript\ncurl -X POST -H \"Authorization: MY_SUPER_APIKEY\"\n```\n\n### Set permission for each Model on 3rd init parameter:\n\n```javascript\nprocess.env.MY_SUPER_APIKEY=31\nacrud.init({\n  keystone: keystone,\n  mongoose: keystone.get('mongoose'),\n}, null, {\n  MY_SUPER_APIKEY: {\n      MyModel: 4 // Read Only\n    }\n    // Other models are full access\n});\n```\n\n## POST request using JSON for data/query/aggregate\n\n```javascript\ncurl -X POST -H \"Authorization: \u003cYOUR_APIKEY\u003e\" -H \"Content-Type: application/json\"\n```\n\n**Available fields:**\n```javascript\n\"body\": {\n  \"id\": \"_id\",\n  \"q\": \"query\",\n  \"s\": \"sort\",\n  \"sk\": \"skip\",\n  \"u\": \"update\",\n  \"o\": \"option\",\n  \"l\": \"limit\",\n  \"f\": \"field\",\n  \"p\": \"populate\",\n  \"dp\": \"deep populate\",\n},\n```\n\n**Require fields per action:**\n\n* save: body is whole object\n* remove: body.q\n* find|findone|count: body.q[s,sk,l,f,p,dp]\n* findid|updateid: body.id\n* update|findoneandupdate: body.q, body.u, body.o\n* aggregate: body is whole aggregate object\n\n**Notes:**\n\n* query, update, aggregate automatically parse with ISO Date String reviver (2015-12-16T09:17:06.307Z)\n* Regex is supported as below example format\n```javascript\n// Basic mongoose example\n{ \"name\" : { $regex: /Ghost/, $options: 'gi' } }\n\n// Use mongoose-acrud, value is replace with: new RegExp(\"Ghost\")\n{\n  \"q\": { \"name\" : { $regex: \"Ghost\", $options: 'gi' } }\n}\n```\n\n## Postman Example\n\nCreate:\n\n```javascript\ncurl -X POST -H \"Authorization: \u003cYOUR_APIKEY\u003e\" -H \"Content-Type: application/json\" -d '{\"key\":\"akey\",\"value\":\"avalue\"}' \"http://localhost:3000/acrud/\u003cYOUR_MODELNAME_CASE_SENSITIVE\u003e/save\"\n```\n\nFind:\n\n```javascript\ncurl -X POST -H \"Authorization: \u003cYOUR_APIKEY\u003e\" -H \"Content-Type: application/json\" -d '{\"q\": {}}' \"http://localhost:3000/acrud/\u003cYOUR_MODELNAME_CASE_SENSITIVE\u003e/find\"\n```\n\nUpdate:\n\n```javascript\ncurl -X POST -H \"Authorization: \u003cYOUR_APIKEY\u003e\" -H \"Content-Type: application/json\" -d '{\n  \"q\": {\"key\":\"key\"},\n  \"u\": {\"value\":\"123456789\"}\n}\n' \"http://localhost:3000/acrud/\u003cYOUR_MODELNAME_CASE_SENSITIVE\u003e/update\"\n```\n\nFind with deep populate:\n\n```javascript\ncurl -X POST -H \"Authorization: \u003cYOUR_APIKEY\u003e\" -H \"Content-Type: application/json\" -d '{\n  \"q\": {\n    \"localDateInt\": 20160815\n  },\n  \"l\": 2,\n  \"dp\": {\n    \"path\": \"skedId.aircraft\",\n    \"select\": \"-_id code\"\n  }\n}\n' \"http://localhost:3000/acrud/\u003cYOUR_MODELNAME_CASE_SENSITIVE\u003e/update\"\n```\n\n## Deep Populate\n\n* Assume that your models are\n\n```javascript\nPlanningGood.add({\n  localDateInt: {\n    type: Number,\n    index: true\n  },\n  skedId: {\n    type: Types.Relationship,\n    ref: 'Sked',\n    many: false,\n    initial: true\n  },\n  aircraft: {\n    type: Types.Relationship,\n    ref: 'Aircraft',\n    many: false,\n    index: true\n  }\n});\n\nSked.add({\n  skedId: {\n    type: String,\n    required: true,\n    initial: true,\n    index: true,\n    unique: true\n  },\n  aircraft: {\n    type: Types.Relationship,\n    ref: 'Aircraft',\n    index: true\n  },\n  flightNumber: {\n    type: Types.Relationship,\n    ref: 'Flight'\n  }\n});\n\nAircraft.add({\n  code: {\n    type: String,\n    index: true,\n    initial: true,\n    required: true\n  }\n});\n\nFlight.add({\n  flightNumber: {\n    type: String,\n    required: true,\n    index: true,\n    initial: true\n  }\n});\n\n```\n\n\"dp\" fields could be\n\n* String (field that need to be populate, could also multi level)\n```javascript\n\"skedId\"\n\"skedId.attds\" // skedId will be populated first, then come the skedId.attds\n```\n* Single object that contain (path, select[optional]):  \n\n```javascript\n{\n  \"path\": \"skedId\", \n  \"select\": \"_id, code\"\n}\n```\n* Array of single object \n\n```javascript\n[\n  {\n    \"path\": \"skedId.aircraft\",\n    \"select\": \"code\"\n  },\n  {\n    \"path\": \"skedId.flightNumber\",\n    \"select\": \"flightNumber\"\n  },\n  {\n    \"path\": \"skedId.attds\"\n  }\n]\n```\n\n### Credit:\n\n * [mongoose-deep-populate](https://www.npmjs.com/package/mongoose-deep-populate) \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalgarter%2Fmongoose-acrud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froyalgarter%2Fmongoose-acrud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalgarter%2Fmongoose-acrud/lists"}