更新コマンドを実行しようとしたときにエラー{ [MongoError: topology was destroyed] name: 'MongoError', message: 'topology was destroyed' }
が実行されています。このエラーの私の理解は、データベース接続が切断されたために発生しますが、モデルへの更新呼び出しであるという意味では意味がありません。ここに私のコードの関連部分は次のとおりです。モンゴースの更新機能で「トポロジが破壊されました」エラー
/*Connect to the Database*/
var options = {
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 60000 } },
replset: { socketOptions: { keepAlive: 1, connectTimeoutMS: 60000 } }
};
var mongoose = require('mongoose'),
ObjectID = mongoose.Types.ObjectId;
mongoose.connect('remote.database', options, function(err) {
if (err) console.log(err);
});
// Schema for single user
var user_schema = mongoose.Schema({
//Username, password information
username: String,
email: String,
password: String,
name: String,
session_ids: [String],
session_id_times: [Number],
//Khan Academy token, secret for accessing tree of knowledge
khan_token: String,
khan_secret: String,
//Callback is for authenticating with khan
khan_callback_id: String,
//Proficiencies (data from khan API)
proficiencies: [String],
additional_skills: [String],
//general recommended skills to learn next
gen_skill_recs: [String]
});
var User = mongoose.model("user_schema", user_schema);
/*
Logins a user without a password after they have authenticated with
Khan. Is only called as a callback to AM.updateAuthentication which
sets khan-callback_id to an empty string so that this only works after
logging on and authenticating with Khan.
*/
exports.loginAfterAuthentication = function(user, callback){
User.findOne({username: user}, function(err, o){
if(err){
callback('server-error');
}else if(o){
var ids = [];
o.session_id_times.forEach(function(el, i) {
if(d.getTime()-el > 24*60*60*14)
ids.push(i);
});
o.session_id_times = o.session_id_times.filter(function(el, i) {return ids.indexOf(i) == -1});
o.session_ids = o.session_ids.filter(function(el, i) {return ids.indexOf(i) == -1});
var session_id = generateSalt();
var session_id_time = d.getTime();
o.session_ids.push(session_id);
o.session_id_times.push(session_id_time);
User.findOneAndUpdate({username: user}, {session_ids: o.session_ids, session_id_times: o.session_id_times}, function(err, o){
if(err)
callback('user-not-found');
else{
callback(null, {'username': user, 'session_id': session_id});
//somewhat time consuming call
API.getUserExercises(o.khan_token, o.khan_secret).then(
function(result){
var addSkills = result;
// call to update proficiencies. Somewhat time consuming
API.getUserInfo(o.khan_token, o.khan_secret).then(
function(result){
var profEx = result.proficient_exercises;
function isntProficient(el){
return profEx.indexOf(el) == -1;
}
// Updates proficiencies and removes additional_skills that have been added to
// proficiencies
console.log(user);
console.log(profEx);
console.log(addSkills.filter(isntProficient));
User.update({username: user},{proficiencies: profEx,
additional_skills: addSkills.filter(isntProficient)}, function(err) {
if(err) callback(err); //This is where this error is triggered
else updateClonesStatuses(user, function(){});
});
}, function(error){
callback('must-reauthenticate', o);
});
}, function(error) {
// if API.getUserInfo() throws an error the user's token
// and secret are depreciated and they must reauthenticate
// with Khan. Should happen very rarely
callback('must-reauthenticate', o);
});
}
});
} else {
callback('user-not-found');
}
});
}
user
は、ユーザーの名前であり、両方profEx
とaddSkills.filter(isntProficient)
は妥当な値です。私はmongoへの接続が何らかの形でどう働くのか誤解していますか?