Is it possible to execute Mongo queries from a code block like we can with SQL?

Answered

I find it useful to write up notes in markdown as I work through something, and embed runnable code snippets. I sometimes have to query some MongoDB collections and record the results, and I currently use the "SQL for Mongo" feature for this because it lets me run the queries from my notes file (this makes it easy to use the "copy to markdown" feature on the query results to quickly paste the results alongside the query).

I'd like to create code blocks like this:

```js (or mongojs, or whatever)
db.getCollection("_User").find({
retailer: "Ed5MKio6Md",
type: "customer",
_created_at: {
$gte: new Date("2021-02-09"),
$lte: new Date("2021-02-16")
}
});
```

These would make more sense outside of the context of IntelliJ, and remove the "middleman" of SQL-for-Mongo.

Am I just missing how to set this up, or is it not currently possible?

0
2 comments
Avatar
Yuriy Vinogradov

unfortunately there is no opportunity to run JS code this way. here is related feature request, please follow and vote.

0

@... Voted & watched — thanks for confirming that I'm not just missing something obvious :-)

0

Please sign in to leave a comment.