--eval EJSON returns TypeError: Converting circular structure to EJSON:

Expecting property name enclosed in double quotes: leads me to attempt to wrap my find query in --eval “EJSON.stringify…” now getting circular reference error. Can I get some guidance to correct my output with double quoted name value pairs. Interestingly, the earlier post that gives example of wrapping db.adminCommand works fine but, db.getCollection does not.

[user204@dev-app1 json]$ mongosh --tls --username xxxdev_usr --password yyy --authenticationDatabase zzz_dev mongodb://stage-zzz.tv:27017/zzz_dev --eval “EJSON.stringify(db.getCollection(‘regions’).find({partner: ‘default’,shortName: ‘CHI’,version: ‘CURRENT’},{ revision: 0}))”
Current Mongosh Log ID: 613f9fd145d2ec22ebbc6fa6
Connecting to: mongodb://stage-zzz.tv:27017/sfp_dev?directConnection=true
Using MongoDB: 4.0.23
Using Mongosh: 1.0.5

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

TypeError: Converting circular structure to EJSON:
(root) → _mongo → __serviceProvider → mongoClient → topology → s → sessionPool → topology

@Harold_Wilson Maybe it helps if you add .toArray() after the .find(...)?

1 Like

and what is the best material/online docs to read about this? the entire result is a single row that I intend to parse. I’ll apologize now, I come from the world of relational data.
Thanks in advance ~H

@Harold_Wilson Fwiw, if you’re thinking about a single row/single document, then .findOne(...) might be a bit nicer. It’s essentially the same as .find(...).next(), which returns the first result of the query.

As for your question, I think in this case https://docs.mongodb.com/manual/tutorial/iterate-a-cursor/ might be helpful, because it documents how users can handle the return value of a .find() call (which is a cursor). However, I can see how both our documentation and the error message in your initial usage of mongosh could be improved. Thanks for bringing this up!

1 Like