{"id":20804853,"url":"https://github.com/manni2000/mongoose","last_synced_at":"2026-04-11T11:37:35.232Z","repository":{"id":170988510,"uuid":"562022659","full_name":"manni2000/Mongoose","owner":"manni2000","description":"Mongoose Documents","archived":false,"fork":false,"pushed_at":"2022-11-10T13:57:50.000Z","size":2492,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T03:33:00.950Z","etag":null,"topics":["database","mongodb","mongoose","nosql"],"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/manni2000.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-05T04:03:12.000Z","updated_at":"2022-11-10T14:29:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"c01c2425-1b74-43e4-8672-8bdb1a22a9dc","html_url":"https://github.com/manni2000/Mongoose","commit_stats":null,"previous_names":["manni2000/mongoose"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/manni2000/Mongoose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manni2000%2FMongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manni2000%2FMongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manni2000%2FMongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manni2000%2FMongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manni2000","download_url":"https://codeload.github.com/manni2000/Mongoose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manni2000%2FMongoose/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267442472,"owners_count":24087805,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","mongodb","mongoose","nosql"],"created_at":"2024-11-17T19:12:11.668Z","updated_at":"2026-04-11T11:37:30.193Z","avatar_url":"https://github.com/manni2000.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cb\u003eMongoose doc\u003cb\u003e\n\n\nFirstly, We will try to understand .. \u003cbr\u003e\u003cbr\u003eWhat is MongoDB?\u003cbr\u003e\n\u003cb\u003eMongoDB\u003cb\u003e is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.\u003cbr\u003e For more details \u003ca href=\"https://www.mongodb.com/docs/\"\u003eDocuments here!\u003c/a\u003e\u003cbr\u003e\n\u003cbr\u003e\u003cbr\u003e Now, You will understand something called Mongoose? ... \u003cbr\u003e\nMongoose is a \u003ca href=\"https://devdocs.io/javascript/\"\u003eJavascript\u003c/a\u003e  object-oriented programming library that creates a connection between MongoDB and the \u003ca href=\"https://nodejs.org/en/docs/\"\u003eNode-js\u003c/a\u003e JavaScript runtime environment.\n\u003cbr\u003e\u003cbr\u003e The following functions are used on the Document of the Mongoose:\u003cbr\u003e\u003cbr\u003e\n\nRetrieving: The document is retrieved by different model functions like findOne(), findById().\u003cbr\u003e\nconst doc = MyModel.findById(myid);\u003cbr\u003e\u003cbr\u003e\nSaving: The document is saved by calling the save function. The function is asynchronous and should be awaited.\u003cbr\u003e\nawait doc.save()\u003cbr\u003e\u003cbr\u003e\nUpdating using save(): The document can be updated by the save() function as follows:\u003cbr\u003e\nawait MyModel.deleteOne({ _id: doc._id });\u003cbr\u003e\u003cbr\u003e\n\ndoc.firstname = 'Manish';\u003cbr\u003e\nawait doc.save();\u003cbr\u003e\u003cbr\u003e\nUpdating using queries: The document can be updated by the queries without calling the save function.\u003cbr\u003e\nawait MyModel.findByIdAndUpdate(myid,{firstname: 'Manish'},function(err, docs){});\u003cbr\u003e\u003cbr\u003e\n\nLet understand after combinating all above function in one example:\u003cbr\u003e\n\u003cbr\u003e We will be using node.js for this example. Node.js and npm should be installed.\u003cbr\u003e\u003cbr\u003e\n\nStep 1: Create a folder and initialize it:\u003cbr\u003e\n\nnpm init\u003cbr\u003e\u003cbr\u003e\nStep 2: Install mongoose in the project.\u003cbr\u003e\n\nnpm i mongoose\u003cbr\u003e\u003cbr\u003e\n\nThe project structure is as follows:\u003cbr\u003e\n![image](https://user-images.githubusercontent.com/91480902/200485353-86efe2e4-02c5-4437-af33-5c3f1d160954.png)\n\u003cbr\u003e\u003cbr\u003e\nStep 3: Create a file called index.js. Inside the index.js, connect to MongoDB. Here the MongoDB Compass is used.\u003cbr\u003e\n\nindex.js\u003cbr\u003e\u003cbr\u003e\n![image](https://user-images.githubusercontent.com/91480902/200485813-11cbaa8a-8568-449c-9130-8b21b8fb7664.png)\u003cbr\u003e\u003cbr\u003e\nStep 4: Now run the code using the following command in the Terminal/Command Prompt to run the file.\u003cbr\u003e\n\nnode index.js\u003cbr\u003e\u003cbr\u003e \nOUTPUT:\u003cbr\u003e\n![image](https://user-images.githubusercontent.com/91480902/200486263-e25b912a-c566-4651-aa46-27f96fbfddc8.png)\n\u003cbr\u003e\u003cbr\u003e\nAnd the document in the MongoDB is as follows:\u003cbr\u003e\n![image](https://user-images.githubusercontent.com/91480902/200486853-461bf734-28a5-430e-982b-9334c848be56.png)\u003cbr\u003e\u003cbr\u003e\nI'm Giving Just Quick Note.\u003cbr\u003e\nIf You like this Repo Give Star Mark.\u003cbr\u003e\nThank You for Reading!\u003cbr\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanni2000%2Fmongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanni2000%2Fmongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanni2000%2Fmongoose/lists"}