{"id":22282902,"url":"https://github.com/leslitech/lesli-nodejs-mongodb-tools","last_synced_at":"2025-03-25T19:46:19.876Z","repository":{"id":38314782,"uuid":"199903851","full_name":"LesliTech/lesli-nodejs-mongodb-tools","owner":"LesliTech","description":"MongoDB wrapper for NodeJS","archived":false,"fork":false,"pushed_at":"2023-04-09T20:52:53.000Z","size":228,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-30T17:38:35.454Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LesliTech.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":"2019-07-31T17:51:05.000Z","updated_at":"2021-12-13T13:54:50.000Z","dependencies_parsed_at":"2025-01-30T17:42:25.760Z","dependency_job_id":null,"html_url":"https://github.com/LesliTech/lesli-nodejs-mongodb-tools","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/LesliTech%2Flesli-nodejs-mongodb-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LesliTech%2Flesli-nodejs-mongodb-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LesliTech%2Flesli-nodejs-mongodb-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LesliTech%2Flesli-nodejs-mongodb-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LesliTech","download_url":"https://codeload.github.com/LesliTech/lesli-nodejs-mongodb-tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245534685,"owners_count":20631288,"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-12-03T16:37:02.841Z","updated_at":"2025-03-25T19:46:19.835Z","avatar_url":"https://github.com/LesliTech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg width=\"175\" alt=\"LesliTech logo\" src=\"https://cdn.lesli.tech/leslitech/brand/leslitech-logo.svg\" /\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003eMongoDB tools for Node.js applications\u003c/h3\u003e\n\n\u003chr/\u003e\n\n**Version 0.10.0** \n\n## Table of Contents\n* [Installation](#installation)\n* [Website \u0026 documentation](#website--documentation)\n* [Get starter](#get-starter)\n* [Usage](#usage)\n    - [Database query](#database-queries)\n    - [Collection query](#collection-queries)\n    - [Document query](#document-queries)\n* [Unit tests](#unit-tests)\n    - [Execute all unit tests](#execute-all-unit-tests)\n    - [Execute specific unit tests](#execute-specific-unit-tests)\n* [Geolocation](./docs/geolocation.md)\n\n### Installation\n--------\n```console\n$  npm install lesli-nodejs-mongodb-tools --save  \n```\n\n### Website \u0026 documentation\n-------\n\nThis software is completely free and open source \n\n* Issue tracker: [https://github.com/LesliTech/lesli-nodejs-mongodb-tools/issues](https://github.com/LesliTech/lesli-nodejs-mongodb-tools/issues)\n\n\n\n## Get starter\n------\nFirst of all, import `lesli-nodejs-mongodb-tools`.  \n```js\nlet { database: Database, collection: Collection, document: Document } = require(\"lesli-nodejs-mongodb-tools\")\n```\n\n\n\n### Usage\n------\nBefore start using the library, create instances of `Database`, `Collection` and `Document`.  \n```js\n    let database = new Document(configuration.database)\n    let collection = new Collection(configuration.database)\n    let document = new Document(configuration.database)\n```\n\n\u003e `configuration.database` comes from [lesli-nodejs-configuration](https://www.npmjs.com/package/lesli-nodejs-configuration)\n\n#### Define a schema\nA `schema` will help us to manage our mongodb inserts, is basically an object with properties: **database** and **collection**.  \u003cbr /\u003e\nExample:\n\n```js\n    const schema = {\n        database: \"buckets\",\n        collection: \"tests\"\n    }\n```\n\n\u003e In the next mongodb methods will be necessary to send a schema as arguments.  \n\n### Database queries\n------\n#### database.read(schema)\nReturn an object with information about a database specified by the given `schema`.  \n\n```js\n    let get_database_information = async(schema) =\u003e {\n\n        // Getting information from database\n        let information = await database.read(schema)\n        console.log(information)\n    }\n```\n\nAll of these methods return promises, so you can use `async` and `await` or only promises with `then` and `catch`.  \u003cbr /\u003e\nLet's see another example:\n\n```js\n    database.read(schema).then(result =\u003e {\n        \n        // Getting information from database\n        let information = result\n        console.log(information)\n\n    }).catch(error =\u003e {\n        console.log(error)\n    })\n```\n\n#### database.delete(schema)\nReturn `true` if the database was deleted successfully.  \u003cbr /\u003e\nExample:\n\n```js\n    let delete_database = async(schema) =\u003e {\n        // Delete all information about a database given\n        let is_deleted = await database.delete(schema)\n\n        if(is_delete){\n            console.log(\"Database has been deleted successful\")\n        }\n\n    }\n\n```\n\n\n\n### Collection queries\n------\n#### collection.read(schema)\nRead information about a collection by the given `schema`.  \u003cbr /\u003e\nExample:\n\n```js\n    let read_collection = async(schema) =\u003e await collection.read(schema)\n```\n\n#### collection.create(schema)\nCreate new collection and return a cursor with information about the collection created.  \u003cbr /\u003e\nExample:\n\n```js\n    let create_collection = async(schema) =\u003e await collection.create(schema)\n```\n\n#### collection.delete(schema)\nDelete a collection, return `true` if everything was successful.  \u003cbr /\u003e\nExample:\n\n```js\n    let delete_collection = async(schema) =\u003e await collection.delete(schema)\n```\n\n#### collection.rename(schema)\nChange the current collection name and put the new by the given `schema`, you have to add a new property into the `schema` object called `new_collection_name`.  \u003cbr /\u003e\nExample:\n\n```js\n    const schema = {\n        database: \"buckets\",\n        collection: \"tests\",\n        new_collection_name: \"new-collection-name\"\n    }\n```\n\nThis method will return an object with database information, such as the new name of the collection and the database name.  \u003cbr /\u003e\nExample:\n\n```js\n    let rename_collection = async(schema) =\u003e {\n\n        let information = await collection.rename(schema\n\n        // Show changes\n        console.log(information) // { db: \"database_name\", collection: \"new_collection_name\" }\n    })\n```\n\n\n\n### Document queries\n------\n#### document.create(schema, document)\nCreate document into the specified collection by the given `schema`. `document` should be an object or JSON with properties key =\u003e value that you want to save. Return information about if everything happened correctly.  \u003cbr /\u003e\nExample:\n\n```js\n    let save_document = async(schema, document) =\u003e {\n        let new_document = await document.create(schema, document)\n\n        // Show information\n        console.log(new_document) // { n: 1, ok: 1, id: ObjectId }\n    }\n\n    save_document(schema, { \"name\": \"bob\", \"lastname\": \"sponge\" })\n```\n\n#### document.find(schema, query?)\nFind documents into the database and collection specified by the given `schema`. With `query` argument is possible to add aggregation pipelines, so you can add a custom query.  \u003cbr /\u003e\nExample: \n\n```js\n    let find_document = async(schema, query = {}) =\u003e await document.find(schema, query)\n```\n\n#### document.first(schema, query?)\nReturn the first document found.  \u003cbr /\u003e\nExample:\n\n```js\n    let first_document = async(schema, query = {}) =\u003e await document.first(schema, query) // {}\n```\n\n\n#### document.update(schema, query, document)\nUpdate one document in the database. You can filter by the given `query`, related to the data you want to update and `document` the new data. \nIn the `query` argument you have tu send an object or JSON with the property `_id` that you want to update.   \nFor example, we are going to update the document created previously.\n\n```js\n    let query = {\n        \"_id\": \"an_id\" // _id should be a valid id of MongoDB\n    }\n\n    let document = {\n        \"name\": \"Tom\",\n        \"lastname\": \"Mate\"\n    }\n\n    let update_one = async(schema, query, document) =\u003e  await document.update(schema, query, document)\n\n    // Call function\n    update_one(schema, query, document)\n```\n\n#### document.delete(schema, query)\nDelete document in a collection, returns an object with information about if everything happend correctly. Should receive `query` argument to filter what document do you want to delete. In the `query` argument you have tu send an object or JSON with the property `_id` that you want to delete.  \u003cbr /\u003e\nExample:\n\n```js\n    let query = {\n        \"_id\": \"an_id\" // _id should be a valid id of MongoDB\n    }\n\n    let delete_document = async(schema, query) =\u003e await document.delete(schema, query)\n    \n    delete_document(schema, query)\n```\n\n#### document.list(schema)\nReturn all documents in a collection. If there are not documents, returns an empty array.   \u003cbr /\u003e\nExample:\n```js\n    let list_documents = async(schema) =\u003e await document.list(schema)\n```\n\n\n### Unit tests\n------\nThis library implements unit tests with [Mocha JS](https://mochajs.org/) and [Chai JS](https://www.chaijs.com/api/bdd/) to validate if all methods saw previously work correctly. There are unit tests for `Database`, `Collection` and `Document`. You can test each of their methods.  \n\n#### Execute all unit tests\nIf you want to test if all methods work correctly, run the next command in your MAC/Linux terminal or Windows CMD.  \u003cbr /\u003e\n\n```console\n$  npm run test\n```\n\n#### Execute specific unit tests\nYou can run specific uni tests either for `Database`, `Collection` or `Document`.  \u003cbr /\u003e\nRun the next commands:\n\n##### Execute unit tests for Databases\n```console\n$  npm run test:query:database\n```\n\n##### Execute unit tests for Collections\n```console\n$  npm run test:query:collection\n```\n\n##### Execute unit tests for Documents\n```console\n$  npm run test:query:document\n```\n\n###### Execute uni tests for Utils\nThese tests are useful for the others tests.  \u003cbr /\u003e\n\n```console\n$  npm run test:utils\n```\n\n### License  \n------\nSoftware developed in [Guatemala](http://visitguatemala.com/) by [LesliTech](https://www.lesli.tech) distributed under the *General Public License v 3.0* you can read the full license [here](http://www.gnu.org/licenses/gpl-3.0.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleslitech%2Flesli-nodejs-mongodb-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleslitech%2Flesli-nodejs-mongodb-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleslitech%2Flesli-nodejs-mongodb-tools/lists"}