$indexStats part 4 mgenerate is not part of mtools use mgeneratejs

I tried to fix this by doing the following:
sudo apt-get install -y npm
npm config set strict-ssl false
sudo npm install -g mgeneratejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
mgeneratejs -n 10000 /shared/mgenerate_userdata.json

now I am seeing this exception:
TypeError: Cannot read property ‘length’ of undefined
at Chance.pickone (/usr/local/lib/node_modules/mgeneratejs/node_modules/chance/chance.js:523:16)
at Object.module.exports [as choose] (/usr/local/lib/node_modules/mgeneratejs/lib/operators/choose.js:31:26)
at callOperator (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:53:25)
at evalValue (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:111:14)
at /usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:13401:38
at /usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:4905:15
at baseForOwn (/usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:2990:24)
at Function.mapValues (/usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:13400:7)
at evalObject (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:72:18)
at evalValue (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:113:12)

any idea?

@Mohammad_89759

Are you running this in the supplied VM or on your own system.

In either case, I would suggest that you start more simply, the most basic mgenerate command

mgeneratejs '{"name": "$name", "age": "$age", "emails": {"$array": {"of": "$email", "number": 3}}}' -n 5

and see if that works. If it does, then try running mgenerate with a much smaller number of records requested – 10000 is a very large set to start with.

Also notice that mgenerate is simply a useful tool to generate data for MongoDB testing, and is nether required nor used in any of the Labs or Exam questions. Also notice that the Quiz for Chapter 2 “Overview Mtools” is out of date, and still shows ‘mgenerate’ as a part of mtools, although it has been removed. Good luck.

I am using vagrant. and the suggested command worked:
mgeneratejs ‘{“name”: “$name”, “age”: “$age”, “emails”: {"$array": {“of”: “$email”, “number”: 3}}}’ -n 5

@Mohammad_89759

Good. Now try running your previous command with ‘-n 10’ and see if that works.

If so, then the size of your test is too large; if not, then you should get a new error message that you can work on.

Hi DHz,

After I followed up the above guide to finish installation of mgereratejs

mgeneratejs ‘{“name”: “$name”, “age”: “$age”, “emails”: {"$array": {“of”: “$email”, “number”: 3}}}’ -n 5 doesn’t work for me.

Generated errors as following:

/usr/local/lib/node_modules/mgeneratejs/node_modules/chance/chance.js:313
let random = options.min + this.natural({max: options.max - option
^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:3:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)

Any ideas? Thanks

Cal

Hi @CALQIU,

Sometimes the terminal is not able to identify the quotes correctly and thus result in syntax error.

Please try to follow the instructions given in the link below and copy the mgenerate command from there:

Please feel free to reach out if you have any questions.

Thanks,
Sonali

Hi Sonali,

Thank you for reply. I have followed https://github.com/rueckstiess/mgeneratejs as well. However I still can’t make it work as follows.

vagrant@m312:~$ npm install -g mgeneratejs

npm http GET https://registry.npmjs.org/mgeneratejs

npm http 304 https://registry.npmjs.org/mgeneratejs

npm ERR! error rolling back Error: EACCES, unlink '/usr/local/bin/mgeneratejs'

npm ERR! error rolling back  mgeneratejs@0.5.1 { [Error: EACCES, unlink '/usr/local/bin/mgeneratejs'] errno: 3, code: 'EACCES', path: '/usr/local/bin/mgeneratejs' }

npm ERR! Error: EACCES, unlink '/usr/local/bin/mgeneratejs'

npm ERR!  { [Error: EACCES, unlink '/usr/local/bin/mgeneratejs'] errno: 3, code: 'EACCES', path: '/usr/local/bin/mgeneratejs' }

npm ERR!

npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Linux 3.13.0-170-generic

npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "mgeneratejs"

npm ERR! cwd /home/vagrant

npm ERR! node -v v0.10.25

npm ERR! npm -v 1.3.10

npm ERR! path /usr/local/bin/mgeneratejs

npm ERR! code EACCES

npm ERR! errno 3

npm ERR! stack Error: EACCES, unlink '/usr/local/bin/mgeneratejs'

npm ERR!

npm ERR! Additional logging details can be found in:

npm ERR!     /home/vagrant/npm-debug.log

npm ERR! not ok code 0

vagrant@m312:~$ sudo npm install -g mgeneratejs

npm http GET https://registry.npmjs.org/mgeneratejs

npm http 304 https://registry.npmjs.org/mgeneratejs

npm http GET https://registry.npmjs.org/bson

npm http GET https://registry.npmjs.org/chance

npm http GET https://registry.npmjs.org/event-stream

npm http GET https://registry.npmjs.org/faker

npm http GET https://registry.npmjs.org/lodash

npm http GET https://registry.npmjs.org/mongodb-extended-json

npm http GET https://registry.npmjs.org/yargs

npm http 304 https://registry.npmjs.org/chance

npm http 304 https://registry.npmjs.org/bson

npm http 304 https://registry.npmjs.org/mongodb-extended-json

npm http 304 https://registry.npmjs.org/yargs

npm http 304 https://registry.npmjs.org/faker

npm http 304 https://registry.npmjs.org/event-stream

npm http 200 https://registry.npmjs.org/lodash

npm http GET https://registry.npmjs.org/lodash.isfunction

npm http GET https://registry.npmjs.org/lodash.transform

npm http GET https://registry.npmjs.org/moment

npm http GET https://registry.npmjs.org/raf

npm http GET https://registry.npmjs.org/JSONStream

npm http GET https://registry.npmjs.org/async

npm http 304 https://registry.npmjs.org/lodash.isfunction

npm http 304 https://registry.npmjs.org/lodash.transform

npm http 304 https://registry.npmjs.org/async

npm http 304 https://registry.npmjs.org/JSONStream

npm http GET https://registry.npmjs.org/duplexer

npm http GET https://registry.npmjs.org/from

npm http GET https://registry.npmjs.org/pause-stream

npm http GET https://registry.npmjs.org/map-stream/0.0.7

npm http GET https://registry.npmjs.org/split

npm http GET https://registry.npmjs.org/stream-combiner

npm http GET https://registry.npmjs.org/through

npm http 304 https://registry.npmjs.org/duplexer

npm http 304 https://registry.npmjs.org/raf

npm http 304 https://registry.npmjs.org/moment

npm http 304 https://registry.npmjs.org/from

npm http 304 https://registry.npmjs.org/split

npm http 304 https://registry.npmjs.org/stream-combiner

npm http 304 https://registry.npmjs.org/through

npm http 200 https://registry.npmjs.org/map-stream/0.0.7

npm http GET https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz

npm http GET https://registry.npmjs.org/performance-now

npm http GET https://registry.npmjs.org/decamelize

npm http GET https://registry.npmjs.org/get-caller-file

npm http GET https://registry.npmjs.org/os-locale

npm http GET https://registry.npmjs.org/read-pkg-up

npm http 304 https://registry.npmjs.org/pause-stream

npm http 304 https://registry.npmjs.org/os-locale

npm http 304 https://registry.npmjs.org/read-pkg-up

npm http GET https://registry.npmjs.org/require-directory

npm http GET https://registry.npmjs.org/require-main-filename

npm http GET https://registry.npmjs.org/which-module

npm http GET https://registry.npmjs.org/set-blocking

npm http GET https://registry.npmjs.org/y18n

npm http GET https://registry.npmjs.org/string-width

npm http GET https://registry.npmjs.org/yargs-parser

npm http GET https://registry.npmjs.org/camelcase

npm http GET https://registry.npmjs.org/cliui

npm http 304 https://registry.npmjs.org/decamelize

npm http 304 https://registry.npmjs.org/performance-now

npm http 200 https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz

npm http 304 https://registry.npmjs.org/require-main-filename

npm http 304 https://registry.npmjs.org/which-module

npm http 304 https://registry.npmjs.org/require-directory

npm http 304 https://registry.npmjs.org/set-blocking

npm http 304 https://registry.npmjs.org/y18n

npm http 304 https://registry.npmjs.org/string-width

npm http 304 https://registry.npmjs.org/yargs-parser

npm http 304 https://registry.npmjs.org/camelcase

npm http 304 https://registry.npmjs.org/cliui

npm http GET https://registry.npmjs.org/jsonparse

npm http 304 https://registry.npmjs.org/jsonparse

npm http 304 https://registry.npmjs.org/get-caller-file

npm http GET https://registry.npmjs.org/find-up

npm http GET https://registry.npmjs.org/code-point-at

npm http GET https://registry.npmjs.org/read-pkg

npm http GET https://registry.npmjs.org/is-fullwidth-code-point

npm http GET https://registry.npmjs.org/strip-ansi

npm http GET https://registry.npmjs.org/lcid

npm http GET https://registry.npmjs.org/strip-ansi

npm http GET https://registry.npmjs.org/wrap-ansi

npm http 304 https://registry.npmjs.org/code-point-at

npm http 304 https://registry.npmjs.org/find-up

npm http 304 https://registry.npmjs.org/read-pkg

npm http 304 https://registry.npmjs.org/is-fullwidth-code-point

npm http 304 https://registry.npmjs.org/strip-ansi

npm http 304 https://registry.npmjs.org/lcid

npm http 304 https://registry.npmjs.org/strip-ansi

npm http 304 https://registry.npmjs.org/wrap-ansi

npm http GET https://registry.npmjs.org/path-exists

npm http GET https://registry.npmjs.org/pinkie-promise

npm http GET https://registry.npmjs.org/load-json-file

npm http GET https://registry.npmjs.org/normalize-package-data

npm http GET https://registry.npmjs.org/ansi-regex

npm http GET https://registry.npmjs.org/path-type

npm http GET https://registry.npmjs.org/number-is-nan

npm http GET https://registry.npmjs.org/invert-kv

npm http 304 https://registry.npmjs.org/path-exists

npm http 304 https://registry.npmjs.org/ansi-regex

npm http 304 https://registry.npmjs.org/path-type

npm http 304 https://registry.npmjs.org/number-is-nan

npm http 304 https://registry.npmjs.org/invert-kv

npm http 304 https://registry.npmjs.org/normalize-package-data

npm http 304 https://registry.npmjs.org/load-json-file

npm http 304 https://registry.npmjs.org/pinkie-promise

npm http GET https://registry.npmjs.org/pify

npm http GET https://registry.npmjs.org/graceful-fs

npm http GET https://registry.npmjs.org/parse-json

npm http GET https://registry.npmjs.org/strip-bom

npm http 304 https://registry.npmjs.org/parse-json

npm http 304 https://registry.npmjs.org/graceful-fs

npm http 304 https://registry.npmjs.org/pify

npm http 304 https://registry.npmjs.org/strip-bom

npm http GET https://registry.npmjs.org/pinkie

npm http GET https://registry.npmjs.org/validate-npm-package-license

npm http GET https://registry.npmjs.org/hosted-git-info

npm http GET https://registry.npmjs.org/resolve

npm http GET https://registry.npmjs.org/semver

npm http 304 https://registry.npmjs.org/pinkie

npm http 304 https://registry.npmjs.org/validate-npm-package-license

npm http 304 https://registry.npmjs.org/semver

npm http GET https://registry.npmjs.org/is-utf8

npm http 304 https://registry.npmjs.org/is-utf8

npm http GET https://registry.npmjs.org/error-ex

npm http 304 https://registry.npmjs.org/error-ex

npm http GET https://registry.npmjs.org/is-arrayish

npm http 304 https://registry.npmjs.org/is-arrayish

npm http 304 https://registry.npmjs.org/hosted-git-info

npm http 200 https://registry.npmjs.org/resolve

npm http GET https://registry.npmjs.org/resolve/-/resolve-1.16.0.tgz

npm http 200 https://registry.npmjs.org/resolve/-/resolve-1.16.0.tgz

npm http GET https://registry.npmjs.org/spdx-correct

npm http GET https://registry.npmjs.org/spdx-expression-parse

npm http 304 https://registry.npmjs.org/spdx-correct

npm http GET https://registry.npmjs.org/path-parse

npm http 304 https://registry.npmjs.org/path-parse

npm http 304 https://registry.npmjs.org/spdx-expression-parse

npm http GET https://registry.npmjs.org/spdx-license-ids

npm http GET https://registry.npmjs.org/spdx-exceptions

npm http 304 https://registry.npmjs.org/spdx-license-ids

npm http 304 https://registry.npmjs.org/spdx-exceptions

/usr/local/bin/mgeneratejs -> /usr/local/lib/node_modules/mgeneratejs/bin/mgenerate.js

mgeneratejs@0.5.1 /usr/local/lib/node_modules/mgeneratejs

├── event-stream@4.0.1 (stream-combiner@0.2.2, duplexer@0.1.1, from@0.1.7, pause-stream@0.0.11, map-stream@0.0.7, split@1.0.1, through@2.3.8)

├── bson@1.1.4

├── chance@1.1.4

├── mongodb-extended-json@1.11.0 (lodash.isfunction@3.0.9, lodash.transform@4.6.0, raf@3.4.1, JSONStream@1.3.5, async@3.2.0, moment@2.24.0)

├── lodash@4.17.15

├── yargs@6.6.1-candidate.4 (decamelize@1.2.0, get-caller-file@1.0.3, which-module@1.0.0, camelcase@3.0.0, set-blocking@2.0.0, y18n@3.2.1, require-main-filename@1.0.1, require-directory@2.1.1, yargs-parser@4.2.1, string-width@1.0.2, os-locale@1.4.0, cliui@3.2.0, read-pkg-up@1.0.1)

└── faker@3.1.0

vagrant@m312:~$ mgeneratejs '{"name": "$name", "age": "$age", "emails": {"$array": {"of": "$email", "number": 3}}}' -n 5

/usr/local/lib/node_modules/mgeneratejs/node_modules/chance/chance.js:313

let random = options.min + this.natural({max: options.max - option

^^^^^^

SyntaxError: Unexpected identifier

at Module._compile (module.js:439:25)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

at Function.Module._load (module.js:312:12)

at Module.require (module.js:364:17)

at require (module.js:380:17)

at Object.<anonymous> (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:3:14)

at Module._compile (module.js:456:26)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

Hi @CALQIU

I’ve just installed a fresh M312 Vagrant box and encountered some of the problems you did. Whilst not recommended in the wider practice, I was able to install it using the superuser / sudo command as follows:

sudo npm install -g mgeneratejs

This may provide a workaround to enable you to continue your work. Let us know if this helps install mgeneratejs on your Vagrant image.

Hope this helps!
Eoin

1 Like

pip alternative:

sudo pip install numpy==1.13.3
sudo pip install mtools==1.2.3  # last version to include mgenerate

… the version is compatible with the “out-of-date” lecture.

NB: this reinforces the need for the Curriculum team to be version specific with all the packages in the provision file

1 Like

Hi Eoin

So glad to get your reply.

I have tried to install it using the superuser / sudo . It seems no error coming out. When I used mgeneratejs it still did not work as follows. Any help is appreciated. Thank you so much!

Cal

vagrant@m312:~$ sudo npm install -g mgeneratejs

npm http GET https://registry.npmjs.org/mgeneratejs

npm http 304 https://registry.npmjs.org/mgeneratejs

npm http GET https://registry.npmjs.org/chance

npm http GET https://registry.npmjs.org/event-stream

npm http GET https://registry.npmjs.org/faker

npm http GET https://registry.npmjs.org/bson

npm http GET https://registry.npmjs.org/lodash

npm http GET https://registry.npmjs.org/mongodb-extended-json

npm http GET https://registry.npmjs.org/yargs

npm http 304 https://registry.npmjs.org/event-stream

npm http 304 https://registry.npmjs.org/lodash

npm http 304 https://registry.npmjs.org/chance

npm http 304 https://registry.npmjs.org/mongodb-extended-json

npm http 200 https://registry.npmjs.org/bson

npm http 200 https://registry.npmjs.org/yargs

npm http 304 https://registry.npmjs.org/faker

npm http GET https://registry.npmjs.org/JSONStream

npm http GET https://registry.npmjs.org/async

npm http GET https://registry.npmjs.org/lodash.transform

npm http GET https://registry.npmjs.org/lodash.isfunction

npm http GET https://registry.npmjs.org/raf

npm http GET https://registry.npmjs.org/moment

npm http 304 https://registry.npmjs.org/JSONStream

npm http 304 https://registry.npmjs.org/async

npm http GET https://registry.npmjs.org/map-stream/0.0.7

npm http GET https://registry.npmjs.org/from

npm http GET https://registry.npmjs.org/duplexer

npm http GET https://registry.npmjs.org/pause-stream

npm http GET https://registry.npmjs.org/stream-combiner

npm http GET https://registry.npmjs.org/split

npm http 304 https://registry.npmjs.org/raf

npm http 304 https://registry.npmjs.org/moment

npm http GET https://registry.npmjs.org/through

npm http 304 https://registry.npmjs.org/duplexer

npm http 304 https://registry.npmjs.org/from

npm http 304 https://registry.npmjs.org/stream-combiner

npm http 304 https://registry.npmjs.org/pause-stream

npm http 304 https://registry.npmjs.org/split

npm http 304 https://registry.npmjs.org/through

npm http 200 https://registry.npmjs.org/map-stream/0.0.7

npm http GET https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz

npm http GET https://registry.npmjs.org/camelcase

npm http GET https://registry.npmjs.org/cliui

npm http GET https://registry.npmjs.org/decamelize

npm http GET https://registry.npmjs.org/os-locale

npm http GET https://registry.npmjs.org/get-caller-file

npm http GET https://registry.npmjs.org/read-pkg-up

npm http GET https://registry.npmjs.org/require-directory

npm http GET https://registry.npmjs.org/require-main-filename

npm http GET https://registry.npmjs.org/set-blocking

npm http GET https://registry.npmjs.org/string-width

npm http GET https://registry.npmjs.org/which-module

npm http GET https://registry.npmjs.org/y18n

npm http GET https://registry.npmjs.org/yargs-parser

npm http 304 https://registry.npmjs.org/camelcase

npm http 304 https://registry.npmjs.org/cliui

npm http 304 https://registry.npmjs.org/decamelize

npm http 304 https://registry.npmjs.org/os-locale

npm http 304 https://registry.npmjs.org/read-pkg-up

npm http 304 https://registry.npmjs.org/get-caller-file

npm http 304 https://registry.npmjs.org/require-directory

npm http 304 https://registry.npmjs.org/require-main-filename

npm http 304 https://registry.npmjs.org/set-blocking

npm http 304 https://registry.npmjs.org/string-width

npm http 304 https://registry.npmjs.org/which-module

npm http 304 https://registry.npmjs.org/y18n

npm http 200 https://registry.npmjs.org/yargs-parser

npm http GET https://registry.npmjs.org/code-point-at

npm http GET https://registry.npmjs.org/is-fullwidth-code-point

npm http GET https://registry.npmjs.org/strip-ansi

npm http GET https://registry.npmjs.org/find-up

npm http GET https://registry.npmjs.org/read-pkg

npm http GET https://registry.npmjs.org/lcid

npm http GET https://registry.npmjs.org/strip-ansi

npm http GET https://registry.npmjs.org/wrap-ansi

npm http 304 https://registry.npmjs.org/is-fullwidth-code-point

npm http 304 https://registry.npmjs.org/code-point-at

npm http 304 https://registry.npmjs.org/strip-ansi

npm http 304 https://registry.npmjs.org/find-up

npm http 304 https://registry.npmjs.org/read-pkg

npm http 304 https://registry.npmjs.org/lcid

npm http 304 https://registry.npmjs.org/strip-ansi

npm http 304 https://registry.npmjs.org/wrap-ansi

npm http GET https://registry.npmjs.org/ansi-regex

npm http GET https://registry.npmjs.org/number-is-nan

npm http GET https://registry.npmjs.org/path-type

npm http GET https://registry.npmjs.org/path-exists

npm http GET https://registry.npmjs.org/pinkie-promise

npm http GET https://registry.npmjs.org/load-json-file

npm http GET https://registry.npmjs.org/normalize-package-data

npm http 304 https://registry.npmjs.org/number-is-nan

npm http 304 https://registry.npmjs.org/ansi-regex

npm http 304 https://registry.npmjs.org/path-type

npm http GET https://registry.npmjs.org/invert-kv

npm http 304 https://registry.npmjs.org/path-exists

npm http 304 https://registry.npmjs.org/pinkie-promise

npm http 304 https://registry.npmjs.org/load-json-file

npm http 304 https://registry.npmjs.org/normalize-package-data

npm http 304 https://registry.npmjs.org/invert-kv

npm http GET https://registry.npmjs.org/pinkie

npm http GET https://registry.npmjs.org/pify

npm http GET https://registry.npmjs.org/graceful-fs

npm http GET https://registry.npmjs.org/strip-bom

npm http GET https://registry.npmjs.org/parse-json

npm http 304 https://registry.npmjs.org/pinkie

npm http 304 https://registry.npmjs.org/graceful-fs

npm http 304 https://registry.npmjs.org/lodash.transform

npm http 304 https://registry.npmjs.org/strip-bom

npm http 304 https://registry.npmjs.org/lodash.isfunction

npm http 304 https://registry.npmjs.org/parse-json

npm http GET https://registry.npmjs.org/hosted-git-info

npm http GET https://registry.npmjs.org/resolve

npm http GET https://registry.npmjs.org/validate-npm-package-license

npm http GET https://registry.npmjs.org/semver

npm http 304 https://registry.npmjs.org/hosted-git-info

npm http 200 https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz

npm http 304 https://registry.npmjs.org/semver

npm http GET https://registry.npmjs.org/performance-now

npm http 304 https://registry.npmjs.org/performance-now

npm http GET https://registry.npmjs.org/jsonparse

npm http 304 https://registry.npmjs.org/pify

npm http GET https://registry.npmjs.org/is-utf8

npm http 304 https://registry.npmjs.org/is-utf8

npm http GET https://registry.npmjs.org/error-ex

npm http 304 https://registry.npmjs.org/validate-npm-package-license

npm http 304 https://registry.npmjs.org/error-ex

npm http GET https://registry.npmjs.org/is-arrayish

npm http 200 https://registry.npmjs.org/resolve

npm http GET https://registry.npmjs.org/resolve/-/resolve-1.16.1.tgz

npm http 200 https://registry.npmjs.org/resolve/-/resolve-1.16.1.tgz

npm http 304 https://registry.npmjs.org/jsonparse

npm http GET https://registry.npmjs.org/spdx-correct

npm http GET https://registry.npmjs.org/spdx-expression-parse

npm http 304 https://registry.npmjs.org/spdx-correct

npm http 304 https://registry.npmjs.org/spdx-expression-parse

npm http GET https://registry.npmjs.org/spdx-license-ids

npm http GET https://registry.npmjs.org/spdx-exceptions

npm http 304 https://registry.npmjs.org/spdx-license-ids

npm http GET https://registry.npmjs.org/path-parse

npm http 304 https://registry.npmjs.org/is-arrayish

npm http 304 https://registry.npmjs.org/path-parse

npm http 200 https://registry.npmjs.org/spdx-exceptions

npm http GET https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz

npm http 200 https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz

/usr/local/bin/mgeneratejs -> /usr/local/lib/node_modules/mgeneratejs/bin/mgenerate.js

mgeneratejs@0.5.1 /usr/local/lib/node_modules/mgeneratejs

├── bson@1.1.4

├── event-stream@4.0.1 (stream-combiner@0.2.2, duplexer@0.1.1, from@0.1.7, pause-stream@0.0.11, map-stream@0.0.7, split@1.0.1, through@2.3.8)

├── chance@1.1.4

├── mongodb-extended-json@1.11.0 (lodash.isfunction@3.0.9, lodash.transform@4.6.0, raf@3.4.1, async@3.2.0, JSONStream@1.3.5, moment@2.24.0)

├── lodash@4.17.15

├── yargs@6.6.1-candidate.4 (decamelize@1.2.0, get-caller-file@1.0.3, which-module@1.0.0, camelcase@3.0.0, set-blocking@2.0.0, y18n@3.2.1, require-main-filename@1.0.1, require-directory@2.1.1, yargs-parser@4.2.1, string-width@1.0.2, os-locale@1.4.0, cliui@3.2.0, read-pkg-up@1.0.1)

└── faker@3.1.0

vagrant@m312:~$

vagrant@m312:~$

vagrant@m312:~$ mgeneratejs '{"name": "$name", "age": "$age", "emails": {"$array": {"of": "$email", "number": 3}}}' -n 5

/usr/local/lib/node_modules/mgeneratejs/node_modules/chance/chance.js:313

let random = options.min + this.natural({max: options.max - option

^^^^^^

SyntaxError: Unexpected identifier

at Module._compile (module.js:439:25)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

at Function.Module._load (module.js:312:12)

at Module.require (module.js:364:17)

at require (module.js:380:17)

at Object.<anonymous> (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:3:14)

at Module._compile (module.js:456:26)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

Hi @CALQIU
cc @Sonali_Mamgain

Thanks for the update, it looks like mgeneratejs installed correctly for you. I’ve replicated exactly the same issue you have encountered where the chance.js module gives the error you posted.

Thank you for including the error as it indeed highlights and underpins @007_jb comment that we are not correctly version pinning our tooling. His previous workaround should resolve the issue which installs the older mgenerate tool (not mgeneratejs, the newer fork of the tool).

If you want a workaround to use mgeneratejs you can do the following:

sudo npm install -g n
sudo n lts
bash
node --version
sudo npm install -g mgeneratejs
mgeneratejs '{"name": "$name", "age": "$age", "emails": {"$array": {"of": "$email", "number": 3}}}' -n 5

N is a helper library which allows you to run multiple versions of node in your machine, we use it to install a more recent version of Node (specifically the current long term support (lts) version, sudo n lts). You then should run a new bash shell (bash) and verify that the node version is now v12.16.2 rather than the previous v0.10.25 (node --version). We then install mgeneratejs (sudo npm install -g mgeneratejs) and retry the example from above with it (mgeneratejs ‘{“name”: “$name”, “age”: “$age”, “emails”: {"$array": {“of”: “$email”, “number”: 3}}}’ -n 5).

Please let me know if this allows you to use the mgeneratejs tool.

On a wider note, we have taken this issue around version pinning as work we need to address. We will be working on this to avoid future reoccurences of this issue. We really appreciate your patience and your help in this issue as it’s helped clarify a genuine error that we will now fix. Our apologies for your time and inconvenience as this was entirely our fault.

I hope you enjoy the rest of the course and please don’t hesitate to ask more questions or flag any new problems to us.

Kindest regards,
Eoin

2 Likes

Perfect Eoin! Great appreciated!

You have a wonderful day!

Cal

Hi all,
I have the same problem as Mohammad_89759, Mohammad Shalabi.

I did what in your post and everything as gone well. But when I try to run mgeneratejs with the file /shared/mgenerate_userdata.json only, I get the same error as following. Now I’m stucked to go ahead with exercise of the course M312. Thank you in advance for all who reply to me.

node:events:505
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read properties of undefined (reading 'length')
    at Chance.pickone (/usr/local/lib/node_modules/mgeneratejs/node_modules/chance/chance.js:663:17)
    at Object.module.exports [as choose] (/usr/local/lib/node_modules/mgeneratejs/lib/operators/choose.js:31:26)
    at callOperator (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:53:25)
    at evalValue (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:117:14)
    at /usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:13469:38
    at /usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:3032:24)
    at Function.mapValues (/usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:13468:7)
    at evalObject (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:72:18)
    at evalValue (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:119:12)
Emitted 'error' event on Stream instance at:
    at Stream.onerror (node:internal/streams/legacy:62:12)
    at Stream.emit (node:events:527:28)
    at Immediate.<anonymous> (/usr/local/lib/node_modules/mgeneratejs/node_modules/event-stream/index.js:176:16)
    at processImmediate (node:internal/timers:466:21)

Try without giving /shared path for the json file and see if it works
You have to be in that dir while running mgenerate

Thank your reply.
I did it, I run in that dir but it didn’t work.

agrant@m312:~/shared$ ls -l
total 16
-rw-r--r-- 1 vagrant vagrant 2330 May 12 16:06 mgenerate_userdata.json
-rw-r--r-- 1 vagrant vagrant  182 May 11 13:21 single.cfg
-rw-r--r-- 1 vagrant vagrant 1403 May 11 14:05 singleapp.py
-rw-r--r-- 1 vagrant vagrant  371 May 12 15:11 template.json
vagrant@m312:~/shared$ mgeneratejs mgenerate_userdata.json
node:events:505
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read properties of undefined (reading 'length')
    at Chance.pickone (/usr/local/lib/node_modules/mgeneratejs/node_modules/chance/chance.js:663:17)
    at Object.module.exports [as choose] (/usr/local/lib/node_modules/mgeneratejs/lib/operators/choose.js:31:26)
    at callOperator (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:53:25)
    at evalValue (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:117:14)
    at /usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:13469:38
    at /usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:3032:24)
    at Function.mapValues (/usr/local/lib/node_modules/mgeneratejs/node_modules/lodash/lodash.js:13468:7)
    at evalObject (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:72:18)
    at evalValue (/usr/local/lib/node_modules/mgeneratejs/lib/index.js:119:12)
Emitted 'error' event on Stream instance at:
    at Stream.onerror (node:internal/streams/legacy:62:12)
    at Stream.emit (node:events:527:28)
    at Immediate.<anonymous> (/usr/local/lib/node_modules/mgeneratejs/node_modules/event-stream/index.js:176:16)
    at processImmediate (node:internal/timers:466:21)
vagrant@m312:~/shared$

Hi all,
I wasn’t able to resolve the above issue, I tried the following:

vagrant@m312:~/shared$ mgeneratejs ‘{“name”: “$name”, “age”: “$age”, “emails”: {"$array": {“of”: “$email”, “number”: 3}}}’ -n 5
{“name”:“Beatrice Elliott”,“age”:26,“emails”:[“zobkoma@fuedki.cu”,“hab@navejti.km”,“jurajpag@ora.kz”]}
{“name”:“Lela Frazier”,“age”:53,“emails”:[“cecaaci@ruobjaj.it”,"deibudo@panca.net",“mugis@vipi.cc”]}
{“name”:“Chad Collier”,“age”:50,“emails”:[“nakwowow@firupa.nc”,“vuj@behirron.so”,“fuf@ve.kg”]}
{“name”:“Trevor Cummings”,“age”:46,“emails”:[“af@osrac.fi”,“himnid@ijwudrev.ps”,“ciwew@suem.it”]}
{“name”:“Duane Lambert”,“age”:34,“emails”:[“ikkaruh@wuduhesu.id”,“gojzen@uhicar.cv”,“caviw@ovi.dk”]}
vagrant@m312:~/shared$ cat

and it works.

I tried again mgeneratejs mgenerate_userdata.json and I get the same error as above, in the previous post.

I tried this: mgeneratejs '{“user”: {“name”: {“first”: {"$choose": [ “Nora”, “Riley”, “Leah”] },“last”: {"$choose": [“Bell”, “Parker”, “Davis”] }}}}'

I get same error.
Anyone has to suggest something to try to solve the issue?
Thank you in advance.

But all above posts say to run with -n which I don’t see in your runs
Are you getting same error with -n also?

Thank you Ramachandra_Tummala but I solved on my own, I was able to go ahed with the exercise course even if the results it wasn’t the same but at least the concept.

I solved because I modificed the mgenerate_userdata.json.

I added on every field where there is the built-in operator $choose the built-in operator $from then the import worked well. Added 10000 documents. Then in the clip of the course there are some examples on the field “phone_no” where in the original mgenerate_userdata.json there is the operator $missing that exclude from import. Then I modified that field to generate a random numbers and complete the example mentioned in the video.

Thanks to everyone who replied to me.

Could you please share the mgenerate_userdata.json you updated? I am stuck in the error TypeError: Cannot read properties of undefined (reading ‘length’)

Hi Mohamed_Shebab the following is the .json file I used to solve the issue. I hope it will be useful to you. Regards.

{
“user”: {
“name”: {
“first”: {"$choose": {“from”: [“Liam”, “Noah”, “Ethan”, “Mason”, “Logan”, “Jacob”, “Lucas”, “Jackson”, “Aiden”, “Jack”, “James”, “Elijah”, “Luke”, “William”, “Michael”, “Alexander”, “Oliver”, “Owen”, “Daniel”, “Gabriel”, “Henry”, “Matthew”, “Carter”, “Ryan”, “Wyatt”, “Andrew”, “Connor”, “Caleb”, “Jayden”, “Nathan”, “Dylan”, “Isaac”, “Hunter”, “Joshua”, “Landon”, “Samuel”, “David”, “Sebastian”, “Olivia”, “Emma”, “Sophia”, “Ava”, “Isabella”, “Mia”, “Charlotte”, “Emily”, “Abigail”, “Avery”, “Harper”, “Ella”, “Madison”, “Amelie”, “Lily”, “Chloe”, “Sofia”, “Evelyn”, “Hannah”, “Addison”, “Grace”, “Aubrey”, “Zoey”, “Aria”, “Ellie”, “Natalie”, “Zoe”, “Audrey”, “Elizabeth”, “Scarlett”, “Layla”, “Victoria”, “Brooklyn”, “Lucy”, “Lillian”, “Claire”, “Nora”, “Riley”, “Leah”] }},
“last”: {"$choose": {“from”: [“Smith”, “Jones”, “Williams”, “Brown”, “Taylor”, “Davies”, “Wilson”, “Evans”, “Thomas”, “Johnson”, “Roberts”, “Walker”, “Wright”, “Robinson”, “Thompson”, “White”, “Hughes”, “Edwards”, “Green”, “Hall”, “Wood”, “Harris”, “Lewis”, “Martin”, “Jackson”, “Clarke”, “Clark”, “Turner”, “Hill”, “Scott”, “Cooper”, “Morris”, “Ward”, “Moore”, “King”, “Watson”, “Baker” , “Harrison”, “Morgan”, “Patel”, “Young”, “Allen”, “Mitchell”, “James”, “Anderson”, “Phillips”, “Lee”, “Bell”, “Parker”, “Davis”] }}
},
“gender”: {"$choose": {“from”: [“female”, “male”]}},
“age”: “$age”,
“address”: {
“street”: {"$string": {“length”: 10}},
“house_no”: “$number”,
“zip_code”: {"$number": [10000, 99999]},
“city”: {"$choose": {“from”: [“Manhattan”, “Brooklyn”, “New Jersey”, “Queens”, “Bronx”]}}
},
“phone_no”: {"$integer": [ 1000000000, 9999999999]} ,
“created_at”: {"$date": [“2010-01-01”, “2014-07-24”] },
“is_active”: {"$choose": {“from”:[true, false]}}
}
}

1 Like