If I have 2 models a.yaml and b,yaml
and if I execute:
fakeit.generate('glob/to/models/**/*.yaml')
.then((data) => {
console.log(data)
})
data is an array like:
[ '[\n {\n "name": "Fahey, Botsford and Schaden",\n "code": "4c49c6c0-8307-4eea-8e67-99b04930e1d2"\n }\n]',
'[\n {\n "name": "Oma",\n "last_name": "Lebsack",\n "username": "Saige.OConnell14",\n "password": "ydKAoYYf8hfWLZJ",\n "email": "Faye.McDermott@gmail.com",\n "phone": "(925) 798-7312"\n }\n]' ]
The question here is, how I can determine which array position is what to be used?
I mean my a.yaml file has defined
and b.yaml
name: Companies
type: object
I need a way to get it something like this:
fakeit.generate('glob/to/models/**/*.yaml')
.then((data) => {
data.foreEach(item => {
const modelName = item.name; // -> this should to have Users|Companies
const records = JSON.parse(item.data); // -> this should contains the serialized data
records.foreEach(record => {
db.collection(modelName).insertOne(record) // on mongo db
})
})
})
Note.- Syntax is only a example like: pseudo-code
Actually there is no way to archive this, because it returns an array of strings and there is no way to know what serialized result is for what source name,
Regards.
If I have 2 models
a.yamlandb,yamland if I execute:
data is an array like:
The question here is, how I can determine which array position is what to be used?
I mean my
a.yamlfile has definedand
b.yamlI need a way to get it something like this:
Note.- Syntax is only a example like: pseudo-code
Actually there is no way to archive this, because it returns an array of strings and there is no way to know what serialized result is for what source name,
Regards.