mongodb-js / mongodb-schema

Infer a probabilistic schema for a MongoDB collection.

Home Page:https://github.com/mongodb-js/mongodb-schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runs in cmd, but not in Git Bash...

curleb opened this issue · comments

Trying to poll a variety of collections across several local MongoDB instances, and I can only get some smaller collections to run successfully. Large collections are hitting some clearLine error, but only in the Bash shell. Runs okay...manually, under Windows:

`C:\Users\bcurley\AppData\Roaming\npm\node_modules\mongodb-schema\node_modules\progress\lib\node-progress.js:177
this.stream.clearLine();
^

TypeError: this.stream.clearLine is not a function
at ProgressBar.terminate (C:\Users\bcurley\AppData\Roaming\npm\node_modules\mongodb-schema\node_modules\progress\lib\node-progress.js:177:17)
at ProgressBar.tick (C:\Users\bcurley\AppData\Roaming\npm\node_modules\mongodb-schema\node_modules\progress\lib\node-progress.js:91:10)
at Stream. (C:\Users\bcurley\AppData\Roaming\npm\node_modules\mongodb-schema\bin\mongodb-schema:179:13)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at Stream.write (C:\Users\bcurley\AppData\Roaming\npm\node_modules\mongodb-schema\lib\stream.js:308:10)
at Stream.stream.write (C:\Users\bcurley\AppData\Roaming\npm\node_modules\mongodb-schema\node_modules\through\index.js:26:11)
at Stream.ondata (internal/streams/legacy.js:16:26)
at emitOne (events.js:101:20)
at Stream.emit (events.js:188:7)
=== `

`for i in $(mongo localhost:27017 --quiet --eval "db.adminCommand('listDatabases')"
|grep -v Hotfix
|grep '"name" :'
|cut -d" -f4
|sed 's/"//g;s/,//g;'
)

Loop through each to compile a listing of existing collections...

do printf "\n%s: \n" "${i}" &&
for j in $(mongo localhost:27017/${i} --quiet --eval "db.getCollectionNames().join('\n')"
|grep -v Hotfix
|sed 's/^/\t/g;'
)

Loop through these to compile a listing of available fields needed on output...

  do printf "\nCREATE TABLE %s ( \n" ${j} \
     && mongodb-schema localhost:27017 --values=false --format=json ${i}.${j} 2>/dev/null \
        |grep '"path":' \
        |cut -d: -f2 \
        |uniq \
        |sed 's/^/         /g;' \
     && printf "         %s ); \n" " \"X\"" 
  done 

done
`
Thoughts?

Looks like a problem with the progress module (that renders the progress bar) on Windows. Other projects had similar issues with the same error message. This one seems to indicate that an upgrade to progress@2.x would fix it: expo/create-react-native-app#179

Turns out the issue is caused by the handling of the sample and repeat variables. My version of Progress was up to speed as it was, but I appreciate the direction.

Works in Windows, but not under Git Bash. Commented the call out for now since my targets are relatively small; mongodb-schema, ln 178-180. I'll see if I can default dummy values explicitly for all platforms in the near-term, although it looks like the optargs section is a little disheveled. I'm not sure why they're misbehaving under Bash, since they're running on the same machine...and Bash is a sub-shell to cmd.

Thanks!