Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Can we embed Mongo shell queries inside Scala code?

Can we embed Mongo shell queries inside Scala code.
If yes, then how.

My main motif is to fetch all the keys in a collection having many documents with different schemas using scala.

Please guide.

Welcome to the community @Harmanat_Singh!

Can you provide an example of your document structure, the query you are trying to develop (or have working in the mongo shell), and your desired output?

If you are using Scala it would be much more reliable and efficient to write your query using the native driver language.

The Scala driver supports the same server-side features as the mongo shell. See the Scala Driver Quick Tour to get started.

Regards,
Stennie