本文介绍了猫鼬多表情错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的模特

var photosSchema = mongoose.Schema({
    username:{
        type: String
    },
    photo: {
        type: String
    },
    caption: {
        type: String
    },
    approved: {
        type: Number,
        default: 0
    }
});

var Photos = module.exports = mongoose.model('photos', photosSchema);

module.exports.getApprovedPhotos = function(username,callback){
Photos.find({username:username,approved:1}).sort({'_id':1}).exec(callback);

}

我想获得批准的照片.我用POSTMAN进行了测试

I want to get approved photo. I test it with POSTMAN

如您所见,我有2个对象,其批准值为0,为什么它会出现在我的提取物中?这是猫鼬中的错误吗?还是我的查询有问题?

As you can see I have 2 object which its approved is 0, how come it can be appear in my fetch? Is this a bug in mongoose? or there's a problem in my query?

推荐答案

如我所见,您没有为approved做任何query.您只是在查询以获取属于username的所有项目.

As I seeing you are not doing any query for approved. You are just giving query to get all items which belong that username.

您还需要为approved属性设置为query试试这个

You need to also give as query for approved property Try this

 module.exports.getPhotosById = function(username,callback){
        Photos.find({username:username,approved:1}).sort({'_id':1}).exec(callback);
    }

这篇关于猫鼬多表情错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 10:16