0

I am new to MongoDB and I have this array saved on it.

The array looks something like this:

{
  playlistArray: [
    {
      title: 'Ocean Man Lyrics',
      url: 'https://www.youtube.com/watch?v=6E5m_XtCX3c',
      duration: '128',
      thumbnail: 'https://i.ytimg.com/vi/6E5m_XtCX3c/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCIpwHcxDNPrcMZYWiqCCK2h-Am8Q'
    },
    {
      title: 'Watermelon Man',
      url: 'https://www.youtube.com/watch?v=4bjPlBC4h_8',
      duration: '392',
      thumbnail: 'https://i.ytimg.com/vi/4bjPlBC4h_8/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLCZGxFxw-tR8NGEtbwITKQqdh8u4w'
    },
    {
      title: 'Smash Mouth - All Star',
      url: 'https://www.youtube.com/watch?v=L_jWHffIx5E',
      duration: '237',
      thumbnail: 'https://i.ytimg.com/vi/L_jWHffIx5E/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLC2FgxHjd2CqZDtYIA9bv1FegnMYA'
    }
  ],
  username: "user name",
  playlistName: "playlist name"
}

However whenever I use mongoose to call the playlistArray array using

        let fetchList;
        fetchList = await playPlaylist.findOne({
            username: username,
            playlistName: playlistName
        });
        let newSongs = fetchList.playlistArray;

The newSongs would return :

[{"title":"Ocean Man Lyrics","url":"https://www.youtube.com/watch?v=6E5m_XtCX3c","duration":"128","thumbnail":"https://i.ytimg.com/vi/6E5m_XtCX3c/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCIpwHcxDNPrcMZYWiqCCK2h-Am8Q"},{"title":"Watermelon Man","url":"https://www.youtube.com/watch?v=4bjPlBC4h_8","duration":"392","thumbnail":"https://i.ytimg.com/vi/4bjPlBC4h_8/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLCZGxFxw-tR8NGEtbwITKQqdh8u4w"},{"title":"Smash Mouth - All Star","url":"https://www.youtube.com/watch?v=L_jWHffIx5E","duration":"237","thumbnail":"https://i.ytimg.com/vi/L_jWHffIx5E/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLC2FgxHjd2CqZDtYIA9bv1FegnMYA"}]

Is there any way for it to return to something like this (remove quotes from the array object)?

[
    {
      title: 'Ocean Man Lyrics',
      url: 'https://www.youtube.com/watch?v=6E5m_XtCX3c',
      duration: '128',
      thumbnail: 'https://i.ytimg.com/vi/6E5m_XtCX3c/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCIpwHcxDNPrcMZYWiqCCK2h-Am8Q'
    },
    {
      title: 'Watermelon Man',
      url: 'https://www.youtube.com/watch?v=4bjPlBC4h_8',
      duration: '392',
      thumbnail: 'https://i.ytimg.com/vi/4bjPlBC4h_8/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLCZGxFxw-tR8NGEtbwITKQqdh8u4w'
    },
    {
      title: 'Smash Mouth - All Star',
      url: 'https://www.youtube.com/watch?v=L_jWHffIx5E',
      duration: '237',
      thumbnail: 'https://i.ytimg.com/vi/L_jWHffIx5E/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLC2FgxHjd2CqZDtYIA9bv1FegnMYA'
    }
]

Any help will be greatly appreciated,

Thanks for reading!

1 Answer 1

1

Solved the problem by using .map()

let newSongs = fetchList.playlistArray.map((arr) => {
   // do something with arr
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.