안녕하세요, 저는 mongodb, mongoose 및 node.js. 나는 몽구스가 어떻게 작동하는지보기 위해 약간의 데모를 만들고 싶다. 설치 (과의 correctes 테스트) 내가 몽구스를 다운로드하고 Node.js를 한 후 (도 몽구스 웹 사이트에서 제공) 다음 코드를 시도 :제공된 데모가있는 몽구스 설정이 작동하지 않습니다.
require.paths.unshift('vendor/mongoose');
var mongoose = require('mongoose').Mongoose;
mongoose.model('User', {
properties: ['first', 'last', 'age', 'updated_at'],
cast: {
age: Number,
'nested.path': String
},
indexes: ['first'],
setters: {
first: function(v){
return this.v.capitalize();
}
},
getters: {
full_name: function(){
return this.first + ' ' + this.last
}
},
methods: {
save: function(fn){
this.updated_at = new Date();
this.__super__(fn);
}
},
static: {
findOldPeople: function(){
return this.find({age: { '$gt': 70 }});
}
}
});
var db = mongoose.connect('mongodb://localhost/db');
var User = db.model('User');
var u = new User();
u.name = 'John';
u.save(function(){
sys.puts('Saved!');
});
User.find({ name: 'john' }).all(function(array){
});
문제는 내가 노드 myfile.js를 실행할 때 내가 가지고 있다는 것입니다 다음과 같은 오류 : 이제
node.js:181
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'mongoose'
at Function._resolveFilename (module.js:320:11)
at Function._load (module.js:266:25)
at require (module.js:364:19)
at Object.<anonymous> (/my/path/to/mongoose+node test/myfile.js:2:16)
at Module._compile (module.js:420:26)
at Object..js (module.js:426:10)
at Module.load (module.js:336:31)
at Function._load (module.js:297:12)
at Array.<anonymous> (module.js:439:10)
at EventEmitter._tickCallback (node.js:173:26)
, 나는 "몽구스 + 노드 테스트"라는 내 폴더에 자바 스크립트 파일들을 포함하고 내부에만 몽구스 폴더를 가지고, 그래서 나는이 정말 새로 온 것을 다시 말할 필요, 그리고 물론 myfile.js. 어쩌면 뭔가 빠졌을까요?
그것은 작동하지 않았다 : (. – Masiar
나중에 단계 일 것입니다. 지금 당장은 당신의 npm이 올바르게 설치되지 않았 음을 분명히 알게됩니다. 그 후 당신은 몽구스를 설치하고 나서야합니다. – neebz
아직 작동하지 않습니다 : /. 지금 어디로 가야할 지 모르겠다 .. – Masiar