{"id":996,"date":"2022-08-30T15:10:39","date_gmt":"2022-08-30T15:10:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/use-npm-packaged-mongoose-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:10:39","modified_gmt":"2022-08-30T15:10:39","slug":"use-npm-packaged-mongoose-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/use-npm-packaged-mongoose-collection-of-common-programming-errors\/","title":{"rendered":"use npm packaged mongoose-Collection of common programming errors"},"content":{"rendered":"<p>In order to &#8220;modularize&#8221; a project, I created several npm packages, but I get an error in two modules that use mongoose.<\/p>\n<p>The first one regroups several operation over the db such connection, map\/reduces, or DAO. The second one regroups all my mongoose model. My packages are stored in <code>\/packages<\/code>.<\/p>\n<p>I am using <code>npm link<\/code> in <code>\/packages<\/code> in all those packages to be able to modify them easily.<\/p>\n<p>Right after connecting mongoose here what i get if i do : console.log(&#8216;mongoose&#8217;)<\/p>\n<pre><code>...\nreplica: false,\nhosts: null,\nhost: 'localhost',\nport: 27017,\nuser: undefined,\npass: undefined,\nname: 'myCollection',\n...\n<\/code><\/pre>\n<p>So mongoose if properly configured.<\/p>\n<p>But in my model&#8217;s package if I do: <code>console.log('mongoose)<\/code> I get:<\/p>\n<pre><code>...\nreplica: null,\nhosts: null,\nhost: null,\nport: null,\nuser: null,\npass: null,\nname: null,\n...\n<\/code><\/pre>\n<p>So when I try to find any of my model, I never get an answer (normal mongoose don&#8217;t know where to search).<\/p>\n<p>I figured out that if I remove all the <code>node_module<\/code> in all packages in <code>\/packages<\/code> it works, but i lost all my dependencies (those I use only in package but not in the main project.)<\/p>\n<p>Does someone have a clue how to solve this problem?<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:11:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>In order to &#8220;modularize&#8221; a project, I created several npm packages, but I get an error in two modules that use mongoose. The first one regroups several operation over the db such connection, map\/reduces, or DAO. The second one regroups all my mongoose model. My packages are stored in \/packages. I am using npm link [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-996","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=996"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/996\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}