• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

배열에 담김 값도 search를 하고싶은데 어떻게 해야하나요?

20.11.26 00:40 작성 조회수 136

0

  1. _id
    :
    5fb52288802e5a696803b338
  2. price
    :
    0
  3. images
    :
    Array
    1. 0
      :
      "uploads\1605706350013_pnkisq_beaj-0_logo.gif"
  4. sold
    :
    0
  5. views
    :
    0
  6. positions
    :
    7
  7. keywords
    :
    Array
    1. 0
      :
      "aaa"
    2. 1
      :
      "fdfdsf"
    3. 2
      :
      "asdas"
    4. 3
      :
      "asd"
  8. writer
    :
    5fad28cb2b442d67dcd773db
  9. title
    :
    "aaa"
  10. description
    :
    "aaa"
  11. deadline
    :
    2020-11-17T15:00:00.000+00:00
  12. createdAt
    :
    2020-11-18T13:32:56.573+00:00
  13. updatedAt
    :
    2020-11-18T13:32:56.573+00:00
  14. __v
    :
    0

keywords 안에 담겨있는 값들도 같이 검색하고 싶습니다

답변 3

·

답변을 작성해보세요.

1

안녕하세요 박정민님 !  

Product 모델에 보시면 


productSchema.index({
title: 'text',
description: 'text'
}, {
weights: {
title: 5,
description: 1
}
})

여기 보시면 검색을 할 필드를 넣어놨기에 
keywords도 추가해주시면 됩니다. 

0

안녕하세요 ~ 
https://docs.mongodb.com/manual/tutorial/control-results-of-text-search/
여기안에 들어가 보시면 배열에 있는것도 검색이 가능하게 되어있습니다 ^^ 
한번 참고해주시면 더 이해가 잘 될거라 생각이됩니다 ~ ! 

0

박정민님의 프로필

박정민

질문자

2020.11.26

//검색 기능에서 검색 우선순위 설정
productSchema.index({
    title: 'text',
    description: 'text',
    keywords: 'text'
},{
    weights:{
        title:5,
        description: 3,
        keywords: 1
    }
})

const Product = mongoose.model('Product', productSchema);

module.exports = { Product }

추가해도 안되길래 ARRAY에 감싸져있어서 안되는건가 싶어서  질문드렸는데 ARRAY에 있는 값을 검색할때도 똑같이  keywords'text' 하면 된다는 말씀이신가요?