2016-08-28 3 views
0

Kürzlich habe ich meinen mongodb-Server vermasselt, aber ich habe ihn repariert und alles läuft glatt außer diesem einen Verzeichnis. Wenn ich Mungo in dieses Verzeichnis NPM installieren zurück, es funktioniert und alles, aber der node_modolus Ordner,NPM installieren Mungo?

door_bells:~/workspace/Associations.1 $ npm install mongoose 
[email protected] ../../node_modules/mongoose 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] ([email protected], [email protected], [email protected]) 
└── [email protected] ([email protected], [email protected], [email protected]) 

auch Pop-up tut vermuten ist, wenn ich versuche, eine js-Datei in diesem Verzeichnis runnning, ist dies der Fehler, den ich bekommen :

door_bells:~/workspace/Associations $ node embed.js 
events.js:141 
     throw er; // Unhandled 'error' event 
    ^

TypeError: Cannot read property 'posts' of null 
    at /home/ubuntu/workspace/Associations/embed.js:56:12 
    at Query.<anonymous> (/home/ubuntu/node_modules/mongoose/lib/model.js:3327:16) 
    at /home/ubuntu/node_modules/mongoose/node_modules/kareem/index.js:259:21 
    at /home/ubuntu/node_modules/mongoose/node_modules/kareem/index.js:127:16 
    at nextTickCallbackWith0Args (node.js:420:9) 
    at process._tickCallback (node.js:349:13) 

var userSchema = new mongoose.Schema({ 
    email: String, 
    name: String, 
    posts: [postSchema] 
}); 
var User = mongoose.model('User', userSchema); 

User.findOne({name: 'sl'}, function(err,user){ 
    if(err) { 
     console.log(err); 
    } else { 
     user.posts.push({ 
      title: '3 Things i really hate', 
      content: 'uuK,SyY,x' 
     }); 
     user.save(function(err,user){ //user save 
      if(err){ 
       console.log(err); 
      } else { 
       console.log(user); 
      } 
     }); 
    } 
}); 
+0

Was ist der Code in embed.js? –

+0

hey, Entschuldigung für die späte Antwort, das ist der Code –

Antwort

0

Ein wenig unklar aus Ihrer Frage, ob Sie eine oder zwei Probleme. Für das 'Posts' Problem kann es sein, dass Sie keinen passenden Benutzer finden. Sie sollten das überprüfen:

User.findOne({name: 'sl'}, function(err,user){ 
if(err) { 
    console.log(err); 
} else { 
    // There is no reason to assume 'user' exists here. Checking for errors would not show this. 
    user.posts.push({ 

So ...

if(user) { 
    user.posts.push({ 

Was Ihre Frage nach node_modules. Nicht ganz klar, ob du tatsächlich ein Problem hast. Es gibt Fälle, in denen die Dinge durcheinander geraten und in diesen Fällen lösche ich den gesamten Ordner node_modules und neu erstellen.

rm -rf node_modules // be sure to be in you project directory - or delete by hand if you prefer 
npm i // Reinstall it all