이 질문은 이전에 게시 된 적이 있지만 내 상황에 대한 수정 사항을 찾을 수없는 것으로 보입니다. 문제를 해결하기 위해 코드를 줄 였지만 아직 해결 방법은 없습니다. - 레코드를 저장하기 위해 Mongoose를 사용한 것은 처음뿐 쿼리에 대한 것이 아니므로 이것이 내 잘못이라고 확신합니다.하지만 제가 시도하는 것은 너무 간단합니다 ... 도와주세요! 미쳤어!몽구스가 저장되지 않음
코드 :
// Constants
var TRUSTED_ORIGIN = "";
var MONGO_SERVER = "mongodb://***.**.**.***/*********";
// Create the database schema
mongoose = require('mongoose');
Schema = mongoose.Schema;
mongoose.connect(MONGO_SERVER);
ObjectId = Schema.ObjectId;
//=============================================================
var UsersSchema = new Schema({
display_name : String,
email : String,
mobile : String,
activated : String,
password : String
});
//=============================================================
//models = require('./models/schemas.js')
var users = mongoose.model('Users',UsersSchema);
//=============================================================
function consoleLogger(msg) {
console.log("*********************************************************");
console.log(msg);
}
"use strict";
var myServer = "http://***.***.**.***/";
process.title = '***********';
// ---------------------------------------------------------------------------------------
// Test Components
consoleLogger("Preparing the first test");
var test1 = "";
console.log("Host: "+mongoose.connection.host);
console.log("Port: "+mongoose.connection.port);
var user_value = new users({display_name: 'Jesse',
email : '[email protected]',
mobile : '******',
activated : 'T',
password : 'Test'});
consoleLogger(user_value);
try {
user_value.save(function(err){
consoleLogger("Item Saved. Err: "+err);
users.find({display_name:'jesse'})
.exec(function(err,data){
consoleLogger("Item Found")
test1 = data[0].display_name
consoleLogger("test1 = "+test1);
});
});
}
catch (e) {
consoleLogger("Failed to save");
}
출력 : 사전에
*********************************************************
Preparing the first test
Host: ***.**.**.***
Port: *****
*********************************************************
{ display_name: 'Jesse',
email: '[email protected]',
mobile: '*********',
activated: 'T',
password: 'Test',
_id: 54995052c17aa7470bfca9e1 }
감사합니다!
유효한 포인트이지만 예, 컬렉션이 존재하지 않는 것을 확인했습니다. 기본적으로 "Item Saved"를 로깅하여 저장 한 확인이 필요합니다. – Jester