Я застрял с чем-то очень глупым, и это заводит меня в орехи.Невозможно использовать объект ответа мангуста
Проблема:
function getPostsCount(callback) {
userPostsModel.findOne({'profileID':req.session.facebookProfileId}, function(err, usersPostCountDB) {
if(usersPostCountDB) {
console.log('usersPostCountDB found and the userPost var passed with it is: ' + usersPostCountDB.postsCount);
console.log(JSON.stringify(usersPostCountDB));
callback(null, usersPostCountDB.postsCount);
} else {
console.log('There was an error getting the postsCount');
callback(true, null);
}
});
}
Вот странная часть, я получаю ниже:
usersPostCountDB found and the userPost var passed with it is: undefined
Кроме того, я посмотрел на ответ следующей строки, и я получаю объект, и это postsCount переменной правильно. Это выглядит примерно так:
Моя схема выглядит, как показано ниже:
var Schema = mongoose.Schema;
var userSchema = new Schema({
profileID: String,
fullname: String,
profilePic: String,
email: String,
birthday: String,
location: String,
about: String,
likes: [],
interests: [],
postsCount: String,
posts: [],
postsAgreed: [],
postsDisagreed: [],
dateCreated: String
});
mongoose.model('user', userSchema, 'users');
Любые идеи всех? Мне действительно нужна помощь на этом этапе.
Спасибо, Шаяно
Похоже, вы не 'postsCount' объявлены в вашей схеме. – robertklep
@robertklep - Я редактировал вопрос, чтобы иметь схему. Как вы теперь видите, он есть. Спасибо –
Да, все в порядке. У вас нет каких-либо промежуточных программ/крюков Mongoose, которые могут вызвать проблему? – robertklep