{"_id":"mongoose-materialized","_rev":"29-88b21024911264a48716d993b0e500dc","name":"mongoose-materialized","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"mongoose-materialized","version":"0.1.0","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.0","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"69f94c2934e17bd2f0ca4f71d648b4eb14f684bb","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.0.tgz","integrity":"sha512-BC7UzUlGs5lUX/7oTPk7a0eQdd8/p/E6Dz65ibJrfkaEZa1MvS2dMXj4EC17VpNaeGqNg8verJsWaLP2+ofEJw==","signatures":[{"sig":"MEUCIBhZftaiNfwUiHxdaBxbChDGSKsSsmEXdOEoVb1dBNomAiEA0X0a4scU7gQkfWEgJqviwoxqlVI3wrfHf1zE5Z0l5lE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.2.32","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.1":{"name":"mongoose-materialized","version":"0.1.1","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.1","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"999e6a8300e22305ecc4c97511438137d7ba403b","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.1.tgz","integrity":"sha512-8tjeVI6l86qT9Hz8pVq1T0EFAOsjjWQOxsD3BLPyWaHQBxvJHughlJ6y/rXYpyFzC+PQNdxbU3OrUPlPz+QqIg==","signatures":[{"sig":"MEYCIQCP0IB/X+kCBdLcNM6Tg983wdvAAshQaXXEb5ylxbwaAgIhAJUb5mDuqIsEa1e1c0TMf1F3sKfyi4GMfbgTy5jaMR4c","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.2.32","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.2":{"name":"mongoose-materialized","version":"0.1.2","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.2","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"ae5dbb5b41b7e8d69513ee47b661c90bdfc29b5c","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.2.tgz","integrity":"sha512-h9bWjqQEro+5o3JP+ZI4rlzgpE4PNaklUqVq6pzZS4UabdKXb/Ero1AL648tk2XdklgYZ4JDr6uugHqcIi+FEg==","signatures":[{"sig":"MEYCIQDMBOVfAB1ZD6+gR/1u14lxeZEZICM96NKeLOlOQoJztgIhALWX/2Aa76p3bE66bk/00gB6l/laoCNOdXqFCmUgBFPC","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.2.32","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.3":{"name":"mongoose-materialized","version":"0.1.3","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.3","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"01a8d225dd53b01a5fbffe5924dc2d7340c01577","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.3.tgz","integrity":"sha512-foSm+TMzw4Pe/qzxrKwn22Ti4cMTuMWz46neQpEypaI94DdjlucO6c+mRYymAz9lp1DNPaXJcZa/qzQslP3XNA==","signatures":[{"sig":"MEQCIBKsQjIx0n2S3KanY7Wqc0hlJNTEBUP84Gn6mFbZ38krAiBOFznGEZOaUjCRqILsNDqtJhOjnGj/IlWJXGo3fiu0/Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.2.32","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.4":{"name":"mongoose-materialized","version":"0.1.4","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.4","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"51ab7cbf03fea0417b95335be30c0cee2f770574","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.4.tgz","integrity":"sha512-deZrmm91EXpXM6kgYJ3ckp4TjW5S7CMgHahrCINjLLDHXoMX9sH/7+VNtcHTNT44GqYzkaslexeQ6E4JBLeyrg==","signatures":[{"sig":"MEQCIB+tzIMJTZXS45LAyIyeNqVWfTRHjJ7phVBUT8wkoRa6AiBDO9LBSUkxpl7Lrkl33TM+n/Chhsg+pBrs5Ed9a2tbLw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.2.32","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.5":{"name":"mongoose-materialized","version":"0.1.5","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.5","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"cdfa743a7e7e6bb3699bb006fd17f7ba7a220dcd","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.5.tgz","integrity":"sha512-8kRjsKz0+EB7bzC+MLYRYHM7COswW1xx8lsRS+ErMxVN7Y/7A1s7dRNUSNPnUc7Ttl2i4hzdnF6wvHp6ypFHSQ==","signatures":[{"sig":"MEUCICfeUot/wn9jE2F6PrZoINKUeTyYjIG8VF9bn/0CFEjiAiEA1bf8drS9WbyZu7Szsbf6f/PqX5HYIPQo7wYPUVfa4jY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.3.11","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.6":{"name":"mongoose-materialized","version":"0.1.6","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.6","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"ab1ef71fb4a5ccb138f80f426b3fabc6af20f4c8","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.6.tgz","integrity":"sha512-Gklf5ZY+juPOHy6xT+lUZD0xBQPBTSJjgoDWB56CUtWtTbXa2rqzOd9Uj2vrSenIzcQT3IwZoB32NYkWjiubRA==","signatures":[{"sig":"MEQCIH2OpmXWVsFR+vgf2X49B6JryOaT7z9BE3u69kdXPzSOAiBP9XZoPR0Ci64EEnqv1LzYrmvfV0Ok9YjzZQZhBadupg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.3.17","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.7":{"name":"mongoose-materialized","version":"0.1.7","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.7","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"ec466df7f0bd8c4a7b40a1cfa07523707bb66194","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.7.tgz","integrity":"sha512-p8uaF7kCHP9xw7g2CQGHDIX5iBzK9NPZpVTwirq2vQarjX+lCVwgA8NuS+jmmaK6e2ILNAde04qZIletTy/Nog==","signatures":[{"sig":"MEYCIQCFxCp+PZeTBXO1P1VLhvh9sasq0w/w/futBs/q0oVGKgIhAKZ/ykhVJjkSgAVKRYWTTGy/dFk9yunFTOxFz32U5Cxl","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","_shasum":"ec466df7f0bd8c4a7b40a1cfa07523707bb66194","gitHead":"4d22f0934a0922705b2a996cc39599358d6787d2","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.4.14","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.2.9","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.8":{"name":"mongoose-materialized","version":"0.1.8","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.8","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"57dbb6a01bbd7f82335a5ff428f5519107975779","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.8.tgz","integrity":"sha512-pZFnhcIkSFEWxNm5/lOQ61Z/d2lCXPpMNUEt1EAsexjiUs/vBIFe2Pu63M3ivj73n6cKsMQwZFu9fs6MZfWmoQ==","signatures":[{"sig":"MEYCIQCkIH3Bmlp8gFtiPPjZSz8jCiR8oGnuSrCMPSESaC1zDAIhAIPXBrBRBvTxW/0+Y6UukA3Yf646GpXfgy1Xq1U/yz2u","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","_shasum":"57dbb6a01bbd7f82335a5ff428f5519107975779","gitHead":"97359881088396b92dcffc0cc315d940b45382d3","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"1.4.21","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"dependencies":{"async":"~0.9.0","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":""}},"0.1.9":{"name":"mongoose-materialized","version":"0.1.9","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.1.9","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"d4d49c1ab0e7d342f80adec491041e06cecdef88","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.1.9.tgz","integrity":"sha512-gpkH1o34H/4BhlAbCJ19ji/gLZXCNl81sdz+vbss9YhLldHhkoCIh88fYP3ff47BBzrWnoSVRl5ePp5d9979rg==","signatures":[{"sig":"MEUCIQCXaIf1/dBDntBK6hEqp3eZNHAnxWK7nUG1W0tNMfdgGwIgMiJJ+G9MGxXvVMQGkLd32jD8jAF8lDghRhmTmW0k3co=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","_from":".","engine":"node >= 0.6.0","_shasum":"d4d49c1ab0e7d342f80adec491041e06cecdef88","gitHead":"55bf18987595fca827593690e10160e98d472198","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"3.10.9","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"_nodeVersion":"6.5.0","dependencies":{"async":"~0.9.0","mongoose":"~3.6.0"},"devDependencies":{"mocha":"~1.8.2","should":"~4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mongoose-materialized-0.1.9.tgz_1478768147588_0.42964242910966277","host":"packages-18-east.internal.npmjs.com"}},"0.2.0":{"name":"mongoose-materialized","version":"0.2.0","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","_id":"mongoose-materialized@0.2.0","maintainers":[{"name":"janez89","email":"mjanee@gmail.com"}],"homepage":"https://github.com/janez89/mongoose-materialized","bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"dist":{"shasum":"9f10454b1db2c4105d43f94a9bb7b0df10162167","tarball":"https://registry.npmjs.org/mongoose-materialized/-/mongoose-materialized-0.2.0.tgz","integrity":"sha512-AS6dVZvk2H10o0xEhOGGoFHvLVd/DMn3js6MDoyx2Vo3/usibmrYacEmLVsP1uewFer0/eat9aRQeO9kh6RAHQ==","signatures":[{"sig":"MEQCIAUV1NaYw8S9ccUYz5flC+eaafumG1AFKOOsEgMx6zqoAiB3QfU/z7tsF5xGa2C4qUzZvRSUQEzcw/MDh94tuMoiTw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index.js","engine":"node >= 0.10.0","gitHead":"7c35758cd0f44b5d227a916b27eb52712b984995","scripts":{"test":"mocha -R spec"},"_npmUser":{"name":"janez89","email":"mjanee@gmail.com"},"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"_npmVersion":"5.0.0","description":"Materialized path hierarchy for mongoose","directories":{"test":"test"},"_nodeVersion":"8.0.0","dependencies":{"async":"~2.5.0","mongoose":"~4.12.0"},"devDependencies":{"mocha":"~1.8.2","should":"~4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mongoose-materialized-0.2.0.tgz_1509198297633_0.7278720200993121","host":"s3://npm-registry-packages"}}},"time":{"created":"2013-07-13T12:17:17.541Z","modified":"2025-12-19T11:33:48.941Z","0.1.0":"2013-07-13T12:17:23.989Z","0.1.1":"2013-07-14T17:47:15.773Z","0.1.2":"2013-07-16T06:44:18.109Z","0.1.3":"2013-07-16T10:32:44.248Z","0.1.4":"2013-07-25T11:49:50.296Z","0.1.5":"2013-10-15T11:38:13.867Z","0.1.6":"2013-12-19T22:23:34.956Z","0.1.7":"2014-07-30T16:07:43.043Z","0.1.8":"2014-08-15T18:55:59.201Z","0.1.9":"2016-11-10T08:55:48.243Z","0.2.0":"2017-10-28T13:44:58.608Z"},"bugs":{"url":"https://github.com/janez89/mongoose-materialized/issues"},"author":{"url":"Janez89","name":"Janos Meszaros","email":"m.janee@gmail.com"},"license":"MIT","homepage":"https://github.com/janez89/mongoose-materialized","keywords":["mongoose","materialized","hierarchic","nested","tree","path","mongodb"],"repository":{"url":"git://github.com/janez89/mongoose-materialized.git","type":"git"},"description":"Materialized path hierarchy for mongoose","maintainers":[{"email":"mjanee@gmail.com","name":"janez"}],"readme":"# Mongoose Materialized\n[![Build Status](https://travis-ci.org/janez89/mongoose-materialized.png?branch=master)](https://travis-ci.org/janez89/mongoose-materialized)\n[![NPM version](https://badge.fury.io/js/mongoose-materialized.png)](http://badge.fury.io/js/mongoose-materialized)\n\nA mongoose plugin for the materialized paths.\n\n## Overview\n* [Usage](#usage)\n* [Examples](#examples)\n* [API](#api)\n  * [Instructions](#instructions)\n  * [Attributes](#attributes)\n  * [Static methods](#static-methods)\n  * [Methods](#methods)\n* [Related Links](#related-links)\n* [Changelog](#changelog)\n* [Authors](#authors)\n\n---\n\n### Usage\n\n```javascript\nvar mongoose = require('mongoose'),\n    materializedPlugin = require('mongoose-materialized'),\n    Schema = mongoose.Schema;\n\nmongoose.connect('mongodb://localhost/materialized');\n\nvar CatSchema = new Schema({\n  name: {type: String}\n});\n\n\nCatSchema.plugin(materializedPlugin);\n\nvar Cat= mongoose.model('Cat', CatSchema); // Category\n```\n\n[Go to contents](#overview)\n\n---\n\n### Examples\n\nAdding root and child element.\n\n**Important**: The model verifies the existence of the parent category before they would save.\nExcept for the root element or change the parent id not touch.\n\n```javascript\n// if you have predefined datas with parent id\nCat.Building(function(){\n    // building materialized path\n});\n\n// add root element\ncat = new Cat({name: \"Foods\"});\ncat.save(function(err, foods){\n    // append new sub category\n    foods.appendChild({name: \"Vegetables\"}, function(err, vega){\n        // vega: { name: \"Vegetables\", parentId: [foods ID], path: ',[foods ID]' }\n    });\n    // or make new\n    var vega = new Cat({name: \"Vegetables\"});\n    // saving with append\n    foods.appendChild(vega, function(err, data){ ... });\n    // or save traditional way\n    vega.parentId = foods._id;\n    vega.save(function(err, data){ ... });\n});\n\n```\n\nFind element and checking the relationship\n```javascript\nCat.findOne({parentId: null}, function(err, doc){\n    // access to the children\n    doc.getChildren(function(err, docs){\n        // ...\n    });\n\n    // access to the children with condition and sort\n    doc.getChildren({\n        condition: { name: /^a/ },\n        sort: { name: 1 }\n    },function(err, docs){\n        // ...\n    });\n\n    // access to the siblings\n    doc.getSiblings(function(err, docs){\n        // ...\n    });\n\n    // access to the ancestors\n    doc.getAncestors(function(err, docs){\n        // ...\n    });\n\n    // check element is root\n    doc.isRoot(function(err, isOk){ ... });\n\n    // check element is leaf\n    doc.isLeaf(function(err, isLeaf){ ... });\n\n    // depth virtual attributes\n    doc.depth\n\n    // use promise\n    doc.getChildren().then(function(docs){\n        // ...\n    });\n\n    // get doc array tree\n    doc.getArrayTree(function(err, tree){\n        // ... [ {\"_id\": \"...\", \"children\": [ {...} ]}]\n    });\n\n    // get doc tree\n    doc.getTree(function(err, tree){\n        // ... { \"doc ID\": { ..., children: { ... } }\n    });\n\n    // or get tree with condition and sorting\n    doc.getTree({\n        condition: { name: /^[a-zA-Z]+$/ },\n        sort: { name: 1 }\n    }, function(err, tree){\n        // ...\n    });\n});\n\nCat.GetTree('elemt ID', function (err, tree) {\n    // ...\n});\n\nCat.GetArrayTree('elemt ID', function (err, tree) {\n    // ...\n});\n\n// access for full tree in array\nCat.GetFullArrayTree(function (err, tree) {\n\n});\n\n// access for full tree object\nCat.GetFullTree(function (err, tree) {\n\n});\n```\n\nThe different arrayTree and simple Tree methods:\narrayTree result: \n```\n[ \n    { _id: 53ee2db76f2d838a07a04e6a,\n    path: '',\n    name: 'Foods',\n    __v: 0,\n    _w: 0,\n    parentId: null,\n    depth: 0,\n    id: '53ee2db76f2d838a07a04e6a',\n    children: [ [Object], [Object] ] \n    }\n]\n```\n\nand the Tree result: \n```\n{ '53ee2db76f2d838a07a04e6a': \n   { _id: 53ee2db76f2d838a07a04e6a,\n     path: '',\n     name: 'Foods',\n     __v: 0,\n     _w: 0,\n     parentId: null,\n     depth: 0,\n     id: '53ee2db76f2d838a07a04e6a',\n     children: { \n        '53ee2db76f2d838a07a04e6b': [Object] \n        } \n    } \n}\n```\n\nManipulate child element with static method\nmongoose-materialized it is possible to use more than one root.\n```javascript\nCat.AppendChild('ID', { 'name': 'Meats'}, function(err, doc){ ... });\nCat.getChildren('ID', function(err, childs){ ... });\nCat.getRoots(function(err, roots){\n    // root elements\n});\n\n// Format tree, sub element stored in children field\nCat.getRoots({ name: \"\" }).then(function (err, root) {\n    root.getChildren().then(function (err, children) {\n        console.log( Cat.toTree(children) );\n        // or only shown name\n        console.log( Cat.toTree(children, { name: 1 }) );\n    });\n});\n\n```\n\nHierarchical builder for the existing data.\n**Important**: This operation is relatively slow. Use only the conversion.\n\n```javascript\nCat.Building(function(){\n    // builded materialized path sturcture\n});\n\n// This example convert nested set to materialized path. Use this function to migration.\n\nCat.Building({\n    remove: { lt: 1, gt: 1, children: 1 } // remove nested fields from existsing data\n}, function(){\n    // building is competted\n});\n```\n\n[Go to contents](#overview)\n\n---\n\n### API\n\n#### Instructions\n\nThe following methods must be used with a callback. The callback method have two arguments. The first error and the second data object.\nIf all goes well then the error is null.\n```javascript\nmodel.calledFunction( function (error, data) {\n    if (error)\n        // handle error\n});\n```\n\nThe methods with work callback return promise. [Mongoose Promise](https://npmjs.org/package/mpromise)\n\n```javascript\nmodel.calledFunction().then( function (data) {\n\n}, function (err) {\n    // handle error\n});\n```\n\n**Imprtant!** Do not use the following methods:\n\n* Model.findByIdAndUpdate()\n* Model.findByOneAndUpdate()\n* Model.findByIdAndRemove()\n* Model.findByOneAndRemove()\n* Model.update() - static version\n* instance.update()\n* Model.remove() - static version\n\nThese functions are not triggered by the removal and saving events.\n\nInstead, the following are recommended:\n\n* instance.save() - saving and update (before use findOne, findById)\n* instance.remove() - remove document (before use findOne, findById)\n* Model.Remove(condition, callback)\n\nThe my ```query``` object is special object for mongo query. This parameter available for functions.\n```javascript\nvar query = {\n    // mongo condition\n    condition: {\n        name: /^a/\n    },\n    // selected fields\n    fields: {\n        _id: 1,\n        name: 1\n    },\n    // sorting\n    sort: {\n        name: -1\n    }\n};\n\n// Example get chidls with query\ndoc.getChilds(query, function(err, docs){ ... });\n```\n\nTo run the tests:\n\n```\nnpm test\n```\n\n[Go to contents](#overview)\n\n---\n\n#### Attributes\nAdded attributes:\n\n* parentId: Parent item id.\n* path: materialized path. Auto generated\n* _w: weight for sort\n* depth: (virtual) element depth\n\n[Go to contents](#overview)\n\n---\n\n#### Static methods\n\nSimilar method has the static begins with the first letter capitalized. (IsLeaft is static and isLeaf non static)\n\n* IsLeaf(ModelOrId, callback)\n* IsRoot(ModelOrId, callback)\n\n* GetChildren(ModelOrId, [query,] callback)\n* GetRoots([query,] callback)\n* GetTree(root condition, [children query,] callback) - get elemets tree with children\n* GetFullTree(callback)\n\n* **GetArrayTree**(root condition, [children query,] callback) - get elemets tree with children\n* **GetFullArrayTree**(callback)\n\n* Remove(condition, callback) - use this instead of remove.\n\n* AppendChild(ModelOrId, callback)\n* ToTree(documentArray, selected fields) Return object, no mongoose document (toObject()). Fields: { name: 1, _id: 1 }\n* ToArrayTree(documentArray, selected fields) Return objects in array, no mongoose document (toObject()). Fields: { name: 1, _id: 1 }\n* Building([prepare,] callback) - rebuild material path (good for extisting collections - parentId is needed)\n\n[Go to contents](#overview)\n\n---\n\n#### Methods\n\n* isRoot(callback)\n* isLeaf(callback)\n* isDescendant(callback)\n* isParent(ModelOrId, callback)\n* isSibling(ModelOrID, callback)\n\n* getParent(callback)\n* getDescendants([query,] callback)\n* getChildren([query,] callback) alias for getDescendants\n* getAncestors([query,] callback)\n* getSiblings([query,] callback)\n* getTree([query,] callback) - get elemets tree with children\n* **getArrayTree([query,] callback)** - get elemets tree with children, array version\n\n* appendChild(model, callback)\n* setParent(ModelOrId) - if parameter is ID then check parent existence and set parentId (the model parameter to avoid the query)\n\n* getChildCondition()\n* getAncestorsCondition()\n* getSiblingsCondition()\n\n[Go to contents](#overview)\n\n---\n\n### Related Links\n\nInspired by seamless data management.\n\n* [MongoDB Model Tree Structures with Materialized Paths](http://docs.mongodb.org/manual/tutorial/model-tree-structures-with-materialized-paths/)\n* [Inspired by mongoose nested set](https://github.com/groupdock/mongoose-nested-set) By @groupdock\n* [MongooseJS Doc](http://mongoosejs.com/)\n\n[Go to contents](#overview)\n\n---\n\n### Changelog\n\n### Oct 28, 2017 - version: 0.2.0\n* fixed update children behavior. Thanks @selcukfatihsevinc\n* updated dependencies: mongoose 4.12.* , Async 2.5.*\n* added support nodejs 8.0\n* dropped support nodejs 0.6, 0.8\n\n### Nov 10, 2016 - version: 0.1.9\n* fixed MongoDB 3.2 limit issue. Thanks @alexjamesbrown\n* fixed dependency: should package\n\n### Aug 15, 2014 - version: 0.1.8\n* added new static methods: **ToArrayTree(), GetArrayTree(), GetFullArrayTree()**\n* added new methods: **getArrayTree()**\n* added new tests\n* enhancements (toTree, parentId type inherits from _id)\n* updated README.md and package dependencies\n\n### July 30, 2014 - version: 0.1.7\n* fixed remove parent with `parentId=null` bug\n* added new tests\n* updated README.md\n\n### Dec 19, 2013 - version: 0.1.6\n* added requested function: skip, limit for getDescendants, getChildren, getAncestors, getSiblings\n* in tree construction (getTree, buildTree) skip, limit methods is not recommended for use\n\n\n### Oct 15, 2013 - version: 0.1.5\n* fixed typo in 153 line.\n\n### Jun 25, 2013 - version: 0.1.4\n* ToTree use virtuals\n* better depth solution\n\n### Jun 16, 2013 - version: 0.1.3\n* added **GetFullTree** static method\n* added prepare for Building - use: Building({ remove: { lt: 1, gt: 1, level: 1 }, function () { });\n* added GetFullTree test\n\n### Jun 16, 2013 - version: 0.1.2\n* added **getTree** method and **GetTree** static method\n* added **Remove** static method for remove with condition\n* fixed: getChildren now return promise\n* fixed: GetRoots function call\n* fixed: GetChildren function call\n* Building method already work\n* Building tests\n* updated README.md\n\n#### Jun 14, 2013 - version: 0.1.1\n* added ToTree test\n* tempory removed Building static method (thown not implemented error if use)\n* fixed: ToTree now return json document. (Not mongoose document)\n* updated README.md\n\n#### Jun 10, 2013 - version: 0.1.0\n* currently under construction\n* added test\n* static methods\n* before save verifies the existence of parent element\n* Query supported methods\n* added Travis CI build status\n* updated README.md\n\n[Go to contents](#overview)\n\n---\n\n### authors\n\n* Janos Meszaros: [https://github.com/janez89](https://github.com/janez89)\n\n[Go to contents](#overview)\n","readmeFilename":"README.md","users":{"mgenev":true,"delacap":true,"clholzin":true}}