강의

멘토링

커뮤니티

Inflearn コミュニティ Q&A

i1004gy6941 のプロフィール画像
i1004gy6941

投稿した質問数

[リニューアル] Node.js教科書 - 基本からプロジェクト実習まで

ハッシュタグを検索する

hashtag set 구현 질문

作成

·

297

0

const arr_hash = req.body.content.match(/#[^\s#]/g);
        const hash_set = new Set(arr_hash)
        const hashtags = new Array()
        hash_set.forEach((element) => {
            hashtags.push(element);
        })
        if (hashtags) {
            const result = await Promise.all(
                hashtags.map(tag => {
                    return Hashtag.findOrCreate({
                        where: { title: tag.slice(1).toLowerCase() },
                    })
                }),
            );
            await post.addHashtags(result.map(r => r[0]));
        }

hashtag를 set으로 만들기 위해서 이렇게 코드를 만들었는데 이렇게 만드니까

GOMCAM 20221008_0831400966.png

데이터 베이스에 이런식으로 글자가 하나만 찍혀서 저장이 됩니다 어떻게 해야하나요?

Sequelizenodejsmongodbmysql

回答 2

0

i1004gy6941님의 프로필 이미지
i1004gy6941
質問者

아 정규식이 이상했네요 감사합니다

0

zerocho님의 프로필 이미지
zerocho
インストラクター

hash_set과 hashtags를 콘솔로그 찍어보세요.

i1004gy6941 のプロフィール画像
i1004gy6941

投稿した質問数

質問する