0

I would like to store each element of the array into separate lines when storing it into NEDB database. Basically using some kind of "\r\n", after every element, as following:

I am basically doing this, right now

usernames = ["name1","name2","name3","name4"]
database.insert({User: usernames})

output:

"User":[["name1","name2","name3","name4"]],"_id":"mNQxEYnTap6QjmQH"}

I have tried chopping the array into using slice and even using \r\n, after every element, but it is still not working, since NEDB doesnt "care" about formatting, as far as i am aware.

My desired output:

"User":[["name1"]],"_id":"..."}
"User":[["name2"]],"_id":"..."}
"User":[["name3"]],"_id":"..."}
"User":[["name4"]],"_id":"..."}

(It is worth mentioning that the data is dynamic, since it is scraped data and there are a few 00' "users")

Any ideas would be highly appreciated.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
JoJo
  • 1
  • 2
  • I wanted to somehow let people know that it is solved, since "You can accept your own answer in 2 days". Anyways, thanks for the heads up – JoJo Sep 18 '22 at 05:25

1 Answers1

0

Found the solution. Split it, so it becomes a "list", as following:

var str = userName.toString().split(',') 
str.forEach((element) => database.insert({fullDate, User: element }))

and you will basically have:

                         str = name1
                               name2
                               name3
                               name4
JoJo
  • 1
  • 2