{"_id":"mongoose-models","_rev":"31-a54b2704f1e73fa516d5d6a66a773f27","name":"mongoose-models","description":"A extension to mongoose's models","dist-tags":{"latest":"0.3.1"},"versions":{"0.0.0":{"name":"mongoose-models","version":"0.0.0","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3"},"_id":"mongoose-models@0.0.0","dist":{"shasum":"07bf5771ef3a2f919b213266b0678498738d0ceb","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.0.0.tgz","integrity":"sha512-DDPmPOv8nd5jYsdEVo4wUgw2ua+ibKABpIMB0VPcUzK5P2Aa/mRK9SrCnuyY1neA2ZtsmhnDLaHO37JOameG8w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDeUySiZ2/UJtHAXXrWV83NUDSgT0v7QfE5BI6wz3iZZQIgGis2A2nbDayqvLQ8Qfs+u4MclWyfnwNzi8sOm/CzRGg="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}],"directories":{}},"0.0.1":{"name":"mongoose-models","version":"0.0.1","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2"},"_id":"mongoose-models@0.0.1","dist":{"shasum":"a0b47b4bfc3ff2897787f980d7dd05aa97d00238","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.0.1.tgz","integrity":"sha512-Se6/CPHHIm2zkDqmced5PZA+aJIXbh6DEeA5tI4+IXYD2ZfJORjOGZ7WLQR6Qh1LSLkvaTwohvnI7UNStqDlAQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAOBG6V6g6FBWEvVCLflrGklVexm8QLTai9rSRn483mQAiEA5F3Mfxznr6ZQwnIi7JNG2OFOl4ysJo1ZX6/xZ5EQp4w="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.0.2":{"name":"mongoose-models","version":"0.0.2","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2"},"_id":"mongoose-models@0.0.2","dist":{"shasum":"1f254edbf6aecc22d2272d331eee7ea35191e031","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.0.2.tgz","integrity":"sha512-SCNS1VGid2FbTS1dOmTk5YQdLqNd3460Onu8SN9lU1zXMAGgQk/RNkye605mD9T0lRXS7GXBHleiagZKXZgNFw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD6mDxxf7zMf4DtefHrq9eRIcI08GrB+bTXpj7iWAPQGAIgCq/B6kOi7oPrA3cw+UMu4vqzEM+F0I2wWSgGnZGZtZE="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.0.3":{"name":"mongoose-models","version":"0.0.3","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2"},"_id":"mongoose-models@0.0.3","dist":{"shasum":"7aa3d006be82a13d7b53c60b2d7bb54b8c9a20b5","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.0.3.tgz","integrity":"sha512-oY2tqY23zOuJObLyoj1ZAQa5hCyN0VaLoqYQ5/f6WEhL48QYjTZGimq9oKJz5aa74RzW3UOfEUe6TRMWSDvBPg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCzcij/x2NxdmQLjIVrknDlWwRUBrCoM4aut+3H/h/wNgIgQQkgL+jRxd+7dJfKsDPgTra8O++A4Y6R7i1UFVzY7bo="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.0.4":{"name":"mongoose-models","version":"0.0.4","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2"},"_id":"mongoose-models@0.0.4","dist":{"shasum":"f478ea760a4e25c46c1697344a7e819219d93572","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.0.4.tgz","integrity":"sha512-2PFj6eUsgVK2luSZ+jHCAX2zr9zmyymh4t8KmWfQ6ny21mLZLEim5BW48Et6VMG6dgWBxhIN5KawBix09sdrhg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBIU6LDAyMAN0tapRtiBJzIYDSCoQYldeJpFW3HD3lC2AiADvIkiww0I8NWI7sXMYAqzbYGdukCspeKpbYwy6Vzmhg=="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.1.0":{"name":"mongoose-models","version":"0.1.0","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2","colors":"0.6.0-1"},"_id":"mongoose-models@0.1.0","dist":{"shasum":"cf272b808f7b513055c7e095beb76e2ee6aa1888","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.1.0.tgz","integrity":"sha512-Dx7qH1FDDO2lFR4HAl+FfXQjSGtbo765ourNkf+AOXrM6tv72wi8DTUPe78B72A7JPG4l1IIbjKKgTekiIddPg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC3ojjIRa/3DRDCV9vWHDhdG7tqA6fbNcirXU3M1Ou1RgIga8U3LR23shT5KzA4dJXvCGFW8hf2RtlBOq6Cc7YIKSg="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.1.1":{"name":"mongoose-models","version":"0.1.1","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2","colors":"0.6.0-1"},"_id":"mongoose-models@0.1.1","dist":{"shasum":"ddb8a35429efd83e46b086837ef0f1548478da2b","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.1.1.tgz","integrity":"sha512-qXfY6B6UN+dQGuAsMOi2dZltVyK2JUKSeUcpTH+C3+fsdNiruK58Ss7faH5++SMfQIofULldJcXW8Tgc0JM+Fw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCDN41hYnRyauy55LJu7lrfbQVBuq2o7Iu4PP7/X+CdqgIhALUtRfV4FGA64Vu1yA6cvZzpkkzVFnZU2hbv6JO794u9"}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.1.2":{"name":"mongoose-models","version":"0.1.2","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2","colors":"0.6.0-1"},"_id":"mongoose-models@0.1.2","dist":{"shasum":"313735fa425d4fcb00cf620759c7bf81197b798f","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.1.2.tgz","integrity":"sha512-VHmahtFeGWz7Gy8X3OTIzEEcpvGGb6PLx9XjV7m0jyDUqXH2cNCvqLZ2r9zne774KStqFQG2SGLz+w2TPAze1Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCY5/SdqJycuYmaiaDegYh/xPFmGeXhsm4zgnGjzrMUCAIgV4X4DwtG0mcMEBUPaUTC4b3Xoy0RmzaOAAt9GNEOI1A="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.2.0":{"name":"mongoose-models","version":"0.2.0","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~2.7.1","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2","colors":"0.6.0-1"},"_id":"mongoose-models@0.2.0","dist":{"shasum":"a42d8102e40365166d1d7180cd174376a3675bff","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.2.0.tgz","integrity":"sha512-7KR2wa1stZRcwrMeFS/R5ZcuD1rL8WneXWbPhzAAYT6t+7yKiiif9X5pZ2f0N6a7cPbEVjoTpv0O2ZMOgm+c6w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBrHsTgjoaALWje/WP9e9QbgLERwBY2bMZJajyFqPrEvAiAkCBtIdSM2WnGWg2j3bTzdz993n0CluY42GQqwQAGu5Q=="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.3.0":{"name":"mongoose-models","version":"0.3.0","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~3.0.0","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"0.0.2","colors":"0.6.0-1"},"_id":"mongoose-models@0.3.0","dist":{"shasum":"8e2e59555abceed2889357dd2bc34009873ccec9","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.3.0.tgz","integrity":"sha512-nvOFINvuDN30d/4peHK/E975ynqanIK7bJX3UseLCQ59jwFt6nggROnZhbv0PWoCkuLiccUpn4aLco5oGvCYuQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDRi3tym2seSb8nTzKHEYDWuHcCvlfsnWa0FXH8WR7pEgIgWS/gLL36vkMkWnqYOfCLoT75hPKRR8nfjF+rmt+Rf4c="}]},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"}]},"0.3.1":{"name":"mongoose-models","version":"0.3.1","description":"A extension to mongoose's models","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"keywords":["mongoose","mongo","db","model"],"author":{"name":"James Brumond"},"license":"MIT","dependencies":{"mongoose":"~3.0.0","wrench":"~1.3.9","mongoose-types":"~1.0.3","uuid-v4":"~0.1.0","colors":"0.6.0-1"},"readme":"# mongoose-models\n\nAn extension of Mongoose's models\n\n## Install\n\n```bash\n$ npm install mongoose-models\n```\n\n## Init\n\n```javascript\nrequire('mongoose-models').init({\n\turl: 'mongodb://localhost/dbname',\n\ttypes: [ 'email', 'url', 'uuid' ],\n\tmodelPath: '/path/to/models/dir'\n});\n```\n\n## Usage\n\n##### models/Person.js\n\n```javascript\nvar models = require('mongoose-models');\n\nvar Person = models.create('Person', {\n\t\n\t// If this is given and truthy, the mongoose-types timestamps\n\t// plugin will be loaded for this model creating automatically\n\t// updating 'createdAt' and 'updatedAt' properties\n\tuseTimestamps: true,\n\t\n\t// Define your mongoose schema here\n\tschema: {\n\t\tfirstName: String,\n\t\tlastName: String,\n\t\t\n\t\t// Special types like Email, Url, and ObjectId can be accessed\n\t\t// through the models.types object\n\t\temail: models.types.Email,\n\t\twebsite: models.types.Url\n\t},\n\t\n\t// Instance methods can be defined here, eg.\n\t//  \n\t//  Person.findOne({ firstName: 'bob' }, function(err, bob) {\n\t//    bob.sendEmail(...);\n\t//  });\n\t//\n\tmethods: {\n\t\t\n\t\tsendEmail: function(subject, msg) {\n\t\t\tsomeMailingLib.sendEmail(this.email, subject, msg);\n\t\t}\n\t\t\n\t},\n\t\n\t// Anything other than the above properties is considered a static\n\t// properties and stored directly on the model, eg.\n\t//\n\t//  Person.findByName('bob', function(err, bob) {\n\t//    ...\n\t//  });\n\t//\n\tfindByName: function(name, callback) {\n\t\tname = name.split(' ');\n\t\tvar lookup = { firstName: name[0] };\n\t\tif (name.length > 1) {\n\t\t\tlookup.lastName = name.pop();\n\t\t}\n\t\tPerson.findOne(lookup, callback);\n\t}\n\t\n});\n```\n\n##### some-other-file.js\n\n```javascript\nvar models = require('mongoose-models');\n\nvar Person = models.require('Person')();\n\nPerson.findByName('bob', function(err, bob) {\n\t\n});\n```\n\n### Circular References\n\nCircular references are rather messy in Mongoose. To make this much easier there is built-in support for circular references in mongoose-models. For example, say you have two models:\n\n##### Foo.js\n\n```javascript\nvar models = require('mongoose-models');\n\nvar Bar = models.require('Bar')();\n\nmodels.create('Foo', {\n\tschema: {\n\t\tbar: { type: models.types.ObjectId, ref: Bar }\n\t}\n});\n```\n\n##### Bar.js\n\n```javascript\nvar models = require('mongoose-models');\n\nvar Foo = models.require('Foo')();\n\nmodels.create('Bar', {\n\tschema: {\n\t\tfoo: { type: models.types.ObjectId, ref: Foo }\n\t}\n});\n```\n\nThis doesn't work because the models are trying to reference each other before they have been created. To make this work, we change the `ref` value like so in both files:\n\n```javascript\n{\n\tbar: { type: models.types.ObjectId, ref: {$circular: 'Bar'} }\n}\n```\n\n```javascript\n{\n\tfoo: { type: models.types.ObjectId, ref: {$circular: 'Foo'} }\n}\n```\n\nNow everything works as expected. There is also a shorter version of this if a model needs to reference itself recursively.\n\n```javascript\nvar models = require('mongoose-models');\n\nmodels.create('Baz', {\n\tschema: {\n\t\tchild: { type: models.types.ObjectId, ref: '$circular' }\n\t}\n});\n```\n\n### models.require(...)\n\nThe `models.require` method that loads models does not return the model directly, but instead returns a function that can be used to fetch the model. This is so that when two models make use of each other, the models are allowed time to set themselves up. That is why models are loaded as `models.require(...)()`. This returned function has a number of properties on it that can be used as well.\n\n#### models.require(...).model\n\nThe model function itself (once defined). This is the same as what is returned from the getter function.\n\n#### models.require(...).schema\n\nThe mongoose schema object. This can be accessed immediately without waiting for the model to be created if you need access sooner. This could be used as an alternative to the `$circular` syntax described above.\n\n#### models.require(...).resolve( callback )\n\nDefines a callback to be run once the model has been created.\n\n```javascript\nvar Foo = models.require('Foo');\nFoo.resolve(function() { Foo = Foo.model; });\n```\n\n### Debugging REPL\n\nThe REPL is a simple JavaScript interpreter with access to your mongoose-models. Before using the REPL, it will need to be loaded and configured.\n\n```bash\n$ cp ./node_modules/mongoose-models/bin/repl.js ./repl.js\n```\n\nNow, open up `repl.js` and change the values in `conf` to match your configuration settings. You can start the REPL by running:\n\n```bash\n$ node repl.js\n```\n\nThe REPL comes with some helpful features on top of the standard node REPL. First, mongoose-models is already loaded for you and is available as `models`. Second, `models.require` has been patched to automatically store loaded models in `global`. There are also some useful functions defined.\n\n```javascript\nLoading REPL...\n> models.require('Foo');\nundefined\n> Foo.find({ }, store('foos'));\n{ ... }\n> \nStored 2 arguments in \"foos\"\n> print(foos);\n{\n  '1': ...\n  '2': ...\n  ...\n}\n```\n\n","readmeFilename":"readme.md","_id":"mongoose-models@0.3.1","dist":{"shasum":"f152b042148e2e7aca1dd7aa56de04a6269729a7","tarball":"https://registry.npmjs.org/mongoose-models/-/mongoose-models-0.3.1.tgz","integrity":"sha512-ZhP4jFvGEgV+lMb5mRPLEgfgIKZKWSimX3UYaAY4HE8LgCj9AtrCvBTXpxChrQAklOJLji/yg3nloIJUDY5+Tw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGW/ty8NReo0T38QFJ06dxNvs3D6AQvNXwkV2w6+MuZWAiEAn59vh/AfAlYrS0IExq7nd0t6+LJOxSZgssuDt77/duc="}]},"_npmVersion":"1.1.65","_npmUser":{"name":"tauren","email":"tauren@sportzing.com"},"maintainers":[{"name":"k","email":"kbjr14@gmail.com"},{"name":"tauren","email":"tauren@sportzing.com"}]}},"readme":"","maintainers":[{"name":"k","email":"kbjr14@gmail.com"},{"name":"tauren","email":"tauren@sportzing.com"}],"time":{"modified":"2022-06-20T07:26:58.987Z","created":"2012-07-08T04:06:40.838Z","0.0.0":"2012-07-08T04:06:42.977Z","0.0.1":"2012-07-08T05:30:57.530Z","0.0.2":"2012-07-08T05:34:51.581Z","0.0.3":"2012-07-08T05:40:19.985Z","0.0.4":"2012-07-08T05:42:15.990Z","0.1.0":"2012-07-25T21:33:09.323Z","0.1.1":"2012-07-25T21:56:28.254Z","0.1.2":"2012-07-25T21:59:02.933Z","0.2.0":"2012-08-04T22:58:56.378Z","0.3.0":"2012-08-09T02:21:10.834Z","0.3.1":"2012-11-18T00:09:08.531Z"},"author":{"name":"James Brumond"},"repository":{"type":"git","url":"git://github.com/SportZing/mongoose-models"},"users":{"fgribreau":true}}