2017-05-16 14 views
0

현재 개체 여기 에서 참조하는 텍스트 인덱스에 관한 문제가 메신저 객체는 "supplierdetails 코드Mongoosejs 텍스트 인덱스

스키마

var UserSchema = new mongoose.Schema({ 
    username: String, 
    fullname: String, 
    email: { 
     type: String, 
     lowercase: true, 
     unique: true 
    }, 
    supplier: Boolean, 
    supplierdetails: { 
    name: String, 
    businesstype: String, 
    location: String, 
    products: String, 
    revenue: String, 
    employees: String, 
    yearsestablished: String 
    } 
}); 
UserSchema.index({supplierdetails: 'text'}); 
module.exports = mongoose.model('User', UserSchema); 

API

router.post('/findsupplier', function(req, res){ 
    User.find({supplier: true, $text: {$search: req.body.supplyData}}, {score: {$meta: 'textScore'}}) 
    .sort({score: {$meta: 'textScore'}}) 
    .exec(function(err, supplyResult){ 
     if(err) 
      throw err; 
     else 
      res.json(supplyResult); 
    }); 
}); 

당신이 여기에서 볼 수 있듯이이다 "내 스키마에있는 개체이며, nam을 포함하는 전체 supplierdetails 개체에서 텍스트 인덱스 검색을 수행하려고하므로 mongoosejs에 텍스트 인덱스를 지정합니다. 전자, businesstype, 제품, 위치 등, 전 생성 된 인덱스 enter image description here

쉘 내 몽고에서 본 그러나 여전히 을 작동하지 않습니다 이것은 내가 검색 데이터베이스 내 데이터

enter image description here

입니다 "dog"또는 "shiba"하지만 여전히 결과가 나타나지 않습니다. 텍스트 인덱스를 사용

내 다른 기능은 유일한 차이는, 내가 텍스트 인덱스를했습니다 하나는 객체가 아닌, 그냥 문자열 속성입니다 완벽하게 작동하고 완벽하게

가 내가 뭐하는 거지 작동 그것은 틀린가?

+0

_shiba_는 'req.body.supplyData'에서 전송됩니까? – Dash

+0

예. 나는 콘솔에 넣으려고했다. 그것을 기록하자. – John

답변

0

documentation에 따르면 String (문자열 포함)이 아닌 String 또는 String of Strings에만 텍스트 색인을 만들 수 있습니다.