{"id":15603299,"url":"https://github.com/codemeasandwich/mongoose-model-restore","last_synced_at":"2025-03-29T13:24:55.326Z","repository":{"id":71445920,"uuid":"467074767","full_name":"codemeasandwich/mongoose-model-restore","owner":"codemeasandwich","description":"should be able to remove and restore a document","archived":false,"fork":false,"pushed_at":"2022-03-07T12:03:32.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-04T14:21:56.620Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemeasandwich.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-07T11:58:42.000Z","updated_at":"2022-03-07T12:03:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"4de86140-fe40-4c7c-83cf-563fd089d04e","html_url":"https://github.com/codemeasandwich/mongoose-model-restore","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"25f5965d8665ffa4e47e0b7f1a6f8242193e7c17"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemeasandwich%2Fmongoose-model-restore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemeasandwich%2Fmongoose-model-restore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemeasandwich%2Fmongoose-model-restore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemeasandwich%2Fmongoose-model-restore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemeasandwich","download_url":"https://codeload.github.com/codemeasandwich/mongoose-model-restore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246188789,"owners_count":20737754,"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-03T03:02:30.210Z","updated_at":"2025-03-29T13:24:55.287Z","avatar_url":"https://github.com/codemeasandwich.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-model-restore\n\na mongoose model generator with a change stream\n\n**info:**\n\n[![npm version](https://badge.fury.io/js/mongoose-model-restore.svg)](https://badge.fury.io/js/graphql-mongoose-model-restore)\n[![License](http://img.shields.io/:license-apache_2-yellow.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n[![pull requests welcome](https://img.shields.io/badge/Pull%20requests-welcome-pink.svg)](https://github.com/codemeasandwich/mongoose-model-restore/pulls)\n\n\n### If this was helpful, [★ it on github](https://github.com/codemeasandwich/mongoose-model-restore)\n\n\n## [Demo / Sandbox](https://tonicdev.com/codemeasandwich/57a0727c80254315001cb366) :thumbsup:\n\n# Install\n\n`npm install mongoose-model-restore`\n\n# Api\n\n``` js\nconst modelPlus = require('mongoose-model-restore');\n```\n\n### constructor\nquery/mutator you wish to use, and an alias or filter arguments.\n\n| Argument (**one** to **two**)  | Description\n|--- |---\n| String | modelNameS: name of model\n| Object | schema: model definition\n| * Bool | (**optional**) enableDownStream = TRUE : Should start listening for changes and __ADD__ stream$ PROP\n\"mongoose-model-stream\" will always push changes, but the '**enableDownStream**' options is wheat you want to also receive changes. \n**e.g.**  a \"**log**\"! you would want to push changes but an a large site. This this would be a lot of traffic, that only an Admin interface would want to listen for.\n\n``` js\nconst ChatSchema = new mongoose.schema({\n  text: String\n});\n\nconst Chat = modelPlus('Chat', ChatSchema);\n``` \n\n### stream$ (think of it like \"find\", but tailing the collection)\nAn [RxJs](http://reactivex.io/rxjs/) [Observable](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html) for change events like ('create', 'update', 'remove' \u0026  ['restore'](https://npmjs.com/codemeasandwich/mongoose-model-restore))\n\n\u003e the event type is a string 'create', 'update', 'remove' or  'restore' \n\u003e **That is set as the object's toSring/valueOf** \n\n``` js\nChat.stream$.map(function (doc) {\n  return doc + ' ' + (doc == \"update\") + ' ' + JSON.stringify(doc) + ' ';\n})\n.subscribe(console.log, // data\nconsole.error, // error\nconsole.info); // close\n\n // \"update true { \"text\":\"bar\", \"id\":\"57ff5d867fb7794f9c52a21f\"}\"\n``` \n\n\n\n## run samples\n\n``` bash\nnode example/sample.js\n```\n\n# Example\n\n``` js \nconst mongoose = require('mongoose');\nconst Schema = mongoose.Schema;\nconst modulePlus = require('mongoose-model-stream');\n\n//=============================================== Logic\nconst ChatSchema = new Schema({  text: String }, { timestamps: true });\n\n//=========================================== generator\nconst ChatDB = modulePlus('Chat', ChatSchema);\n\n//===================================== start listening\nChatDB.stream$.subscribe(console.log, console.error, console.info);\n\n//======================================= start example\nsetTimeout(function () {\n\n//+++++++++++++++++++++++++++++++++++++++++++++ create\n  ChatDB.create({ text: \"foo\" })\n  .then(function (chatMessage) {\n\n    console.log(\" \u003e\u003e FROM \", 'text = \"' + chatMessage.text + '\"');\n    chatMessage.text = \"bar\";\n    console.log(\" \u003e\u003e TO \", 'text = \"' + chatMessage.text + '\"');\n\n//+++++++++++++++++++++++++++++++++++++++++++++ update\n    return chatMessage.save();\n  }).then(function (chatMessage) {\n\n    setTimeout(function () {\n\n      console.log(\" \u003e\u003e\u003e FROM \", 'text = \"' + chatMessage.text + '\"');\n      chatMessage.text = \"baz\";\n      console.log(\" \u003e\u003e\u003e TO \", 'text = \"' + chatMessage.text + '\"');\n\n//+++++++++++++++++++++++++++++++++++++++++++++ update\n\n      chatMessage.save();\n    }, 1000);\n  });\n}, 1000);\n    \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemeasandwich%2Fmongoose-model-restore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemeasandwich%2Fmongoose-model-restore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemeasandwich%2Fmongoose-model-restore/lists"}