0

I want write a script using node js, which will execute certain raw mongo queries. Is there a way to do that?

Ex: mongoose.exec('db.<collection>.find({})');

Is there a way to achieve something like above?

Jagajit Prusty
  • 2,070
  • 2
  • 21
  • 39
  • You'd be better off using the native driver for this instead of mongoose. – JohnnyHK May 07 '16 at 14:49
  • @JohnnyHK this application db connection are written in mongoose so can't change that. – Jagajit Prusty May 07 '16 at 14:52
  • @JohnnyHK I just gave one example. That question only tells how to delete a collection using mongoose. But my question is how to execute any raw mongo db queries. I would be thankful if you can remove the duplicate mark. Changed example also. – Jagajit Prusty May 07 '16 at 18:17
  • Sure, but the linked duplicate shows you how to access the native [`Db`](http://mongodb.github.io/node-mongodb-native/2.0/api/Db.html) object that lets you do whatever you want. For your other example it's the same approach: `mongoose.connection.db.collection('collection').find({})`. – JohnnyHK May 07 '16 at 18:37

0 Answers0