{"id":18022998,"url":"https://github.com/kanryu/puremongo","last_synced_at":"2025-04-04T18:17:35.100Z","repository":{"id":12932193,"uuid":"15609927","full_name":"kanryu/puremongo","owner":"kanryu","description":"A pure JavaScript clone for MongoDB","archived":false,"fork":false,"pushed_at":"2022-01-16T20:33:59.000Z","size":184,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T03:26:50.803Z","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/kanryu.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":"2014-01-03T13:20:44.000Z","updated_at":"2023-05-08T17:47:21.000Z","dependencies_parsed_at":"2022-07-10T04:46:28.624Z","dependency_job_id":null,"html_url":"https://github.com/kanryu/puremongo","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/kanryu%2Fpuremongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fpuremongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fpuremongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fpuremongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanryu","download_url":"https://codeload.github.com/kanryu/puremongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226191,"owners_count":20904467,"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-30T07:06:35.612Z","updated_at":"2025-04-04T18:17:35.073Z","avatar_url":"https://github.com/kanryu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PureMongo - a pure JavaScript clone for MongoDB\n \n\n### Questions and Bug Reports\n\n * e-mail: k.kanryu@gmail.com\n * twitter: @junzabroP\n\n## Install\n\nJust use puremongo.js! :)\n\n\n## Live Examples\n\u003ca href=\"https://runnable.com/node-mongodb-native\" target=\"_blank\"\u003e\u003cimg src=\"https://runnable.com/external/styles/assets/runnablebtn.png\" style=\"width:67px;height:25px;\"\u003e\u003c/a\u003e\n\n## Introduction\n\nThis is a pure JavaScript clone for MongoDB. This API is similar to at https://github.com/mongodb/node-mongodb-native .\n\nYou can run the DB on node.js, on Common.js, even on web browsers.\n\nA simple example of inserting a document.\n\n```javascript\n  //var MongoClient = require('mongodb').MongoClient\n  //  , format = require('util').format;\n  var MongoClient = require('./puremongo').MongoClient\n    , format = require('util').format;\n\n  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {\n    if(err) throw err;\n\n    var collection = db.collection('test_insert');\n    collection.insert({a:2}, function(err, docs) {\n      \n      collection.count(function(err, count) {\n        console.log(format(\"count = %s\", count));\n      });\n\n      // Locate all the entries using find\n      collection.find().toArray(function(err, results) {\n        console.dir(results);\n        // Let's close the db\n        db.close();\n      });\n    });\n  })\n```\n\nCurrently, puremongo doesn't have any function as a network server, only in-process working.\n\n\n## GitHub information\n\nThe source code is available at http://github.com/kanryu/puremongo\nYou can either clone the repository or download a tarball of the latest release.\n\n### Find\n\nThe find method is actually a factory method to create\nCursor objects. A Cursor lazily uses the connection the first time\nyou call `toArray`.\n\nThe basic operation on a cursor is the `nextObject` method\nthat fetches the next matching document from the database. The convenience\nmethods `each` and `toArray` call `nextObject` until the cursor is exhausted.\n\nSignatures:\n\n```javascript\n  var cursor = collection.find(query, [fields], options);\n  cursor.sort(fields).limit(n).skip(m);\n\n  cursor.toArray(function(err, docs) {});\n```\n\nUseful chainable methods of cursor. These can optionally be options of `find` instead of method calls:\n\n  * `.limit(n).skip(m)` to control paging.\n  * `.sort(fields)` Order by the given fields. There are several equivalent syntaxes:\n  * `.sort({field1: -1, field2: 1})` descending by field1, then ascending by field2.\n\nOther options of `find`:\n\n* `fields` the fields to fetch (to avoid transferring the entire document)\n* `tailable` if true, makes the cursor [tailable](http://www.mongodb.org/display/DOCS/Tailable+Cursors).\n* `batchSize` The number of the subset of results to request the database\nto return for every request. This should initially be greater than 1 otherwise\nthe database will automatically close the cursor. The batch size can be set to 1\nwith `batchSize(n, function(err){})` after performing the initial query to the database.\n\nFor information on how to create queries, see the\n[MongoDB section on querying](http://www.mongodb.org/display/DOCS/Querying).\n\n```javascript\n  var MongoClient = require('mongodb').MongoClient\n    , format = require('util').format;    \n\n  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {\n    if(err) throw err;\n\n    var collection = db\n      .collection('test')\n      .find({})\n      .toArray(function(err, docs) {\n        console.dir(docs);\n    });\n  });\n```\n\n### Insert\n\nSignature:\n\n```javascript\n  collection.insert(docs, options, [callback]);\n```\n\nwhere `docs` can be a single document or an array of documents.\n\nUseful options:\n\n* `safe:true` Should always set if you have a callback.\n\nSee also: [MongoDB docs for insert](http://www.mongodb.org/display/DOCS/Inserting).\n\n```javascript\n  var MongoClient = require('mongodb').MongoClient\n    , format = require('util').format;    \n\n  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {\n    if(err) throw err;\n    \n    db.collection('test').insert({hello: 'world'}, {w:1}, function(err, objects) {\n      if (err) console.warn(err.message);\n      if (err \u0026\u0026 err.message.indexOf('E11000 ') !== -1) {\n        // this _id was already inserted in the database\n      }\n    });\n  });\n```\n\nNote that there's no reason to pass a callback to the insert or update commands\nunless you use the `safe:true` option. If you don't specify `safe:true`, then\nyour callback will be called immediately.\n\n### Update: update and insert (upsert)\n\nThe update operation will update the first document that matches your query\n(or all documents that match if you use `multi:true`).\nIf `safe:true`, `upsert` is not set, and no documents match, your callback will return 0 documents updated.\n\nSee the [MongoDB docs](http://www.mongodb.org/display/DOCS/Updating) for\nthe modifier (`$inc`, `$set`, `$push`, etc.) formats.\n\nSignature:\n\n```javascript\n  collection.update(criteria, objNew, options, [callback]);\n```\n\nUseful options:\n\n* `upsert:true` Atomically inserts the document if no documents matched.\n\nExample for `update`:\n\n```javascript\n  var MongoClient = require('mongodb').MongoClient\n    , format = require('util').format;    \n\n  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {\n    if(err) throw err;\n\n    db.collection('test').update({hi: 'here'}, {$set: {hi: 'there'}}, {w:1}, function(err) {\n      if (err) console.warn(err.message);\n      else console.log('successfully updated');\n    });\n  });\n```\n\n\n### Save\n\nThe `save` method is a shorthand for upsert if the document contains an\n`_id`, or an insert if there is no `_id`.\n\n## Tests\n```shellscript\n  $ mocha test_*.js\n```\n\n## License\n\n Copyright 2014 KATO Kanryu\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanryu%2Fpuremongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanryu%2Fpuremongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanryu%2Fpuremongo/lists"}