Closed akshay2604 closed 7 years ago
Can you provide the products.yaml
here and if there're other dependencies could you create a gist and just post the link.
products.yaml
name: Products
type: object
key:
data:
build: `user_${this.user_id}`
data:
inputs: /Users/sahusoft/Sites/projects/cloud9pg-api/input/product.json, /Users/sahusoft/Sites/projects/cloud9pg-api/input/abc.json
pre_run: |
console.log("inputs", inputs)
globals.user_counter = 0;
properties:
_id:
type: string
description: The document id
data:
build: |
return require('/Users/sahusoft/Sites/projects/cloud9pg-api/node_modules/mongoose').Types.ObjectId()
xAddr:
type: object
properties:
xCO:
data:
fake: '{{address.secondaryAddress}}'
xLine1:
data:
fake: '{{address.secondaryAddress}}'
xLine2:
data:
fake: '{{address.streetAddress}}'
xCity:
data:
fake: '{{address.city}}'
xSOP:
data:
fake: '{{address.state}}'
xPostCode:
data:
fake: '{{address.zipCode}}'
xCountry:
data:
fake: '{{address.country}}'
So It looks like the problem is the way you are creating the key
which is what determines what the name of the document is.
key:
data:
build: `user_${this.user_id}`
Here you're returning a key of user_undefined
every time which is why you're only seeing 1 file generated because each document that's generated overwrites the last one. The reason for this is that this.user_id
isn't defined because you haven't defined that property yet
properties:
_id:
type: string
description: The document id
data:
build: require('/Users/sahusoft/Sites/projects/cloud9pg-api/node_modules/mongoose').Types.ObjectId()
user_id:
type: string
data:
build: faker.random.uuid()
Here's what the output is after adding the user_id
property.
The following doesn't have anything to do with the problem just a helpful tip that will hopefully make things easier for you.
Also it looks like you're in the folder of /Users/sahusoft/Sites/projects/cloud9pg-api
and the way this project works is by using relative paths. So instead of specifying the absolute path which will only work on your computer it's better to specify them like this.
data:
inputs:
- input/product.json
- input/abc.json
Also node works very similarly. So for the properties._id.data.build
all you need is require('mongoose').Types.ObjectId()
because node will look inside of the node_modules
directory for the folder mongoose
and then look at it's package.json
to find the main file to import.
Hey, Thanks for that. It worked. But how to get all the output in one file instead?
⠋ Products[19:17:56] ✖ error: { Error: propertiesIdDataBuild failed, Cannot find module 'mongoose'.
This error occurs if i remove the the absolute path and write require('mongoose').Types.ObjectId()
for input removing absolute path works fine
It looks like there is a bug with that, I will open an issue to look into that. For now you'll have to keep the require
statements as full paths.
As for getting it to output into a single file we currently don't support that. I've thought about adding support for it but I haven't got around to it yet.
For now here's an easy way to do what I think you're wanting to do.
mkdir -p output && fakeit console products.yaml --count 10 >> output/users.json
@akshay2604 If you update to fakeit to 1.2.1 you should now be able to require mongoose
correctly require('require')
Thanks @tjbenton really appreciate it.
Writing something like this
fakeit directory output products.yaml --count 3
results inoutput/user_undefined.json
However running
fakeit console products.yaml --count 3
is producing the desired output.File is saved with UTF-8 encoding.