[SOLVED] How do I store data into nedb on multiple lines?

Issue

This Content is from Stack Overflow. Question asked by JoJo

I would like to store each element of the array into separate lines when storing it into nedb. Basically using some kind of “rn”, 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 rn, 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.



Solution

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


This Question was asked in StackOverflow by JoJo and Answered by JoJo It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?