Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a raw mongodb query in loopback

How can I execute a raw mongo db query in loopback remote method? I tried like:

    Members.getDataSource().connector.connect(function (err, db) {
          var collection = db.collection('Members');
          var res = collection.find();
          console.log(res);
   });

Here, res gives me a huge amount of data inside an object, but I cant find any result documents from that object. Any help will be appreciated! Thanks !

like image 330
Phoenix Dev Avatar asked May 26 '26 07:05

Phoenix Dev


1 Answers

It is async too.

    Members.getDataSource().connector.connect(function (err, db) {
          var collection = db.collection('member_col'); //name of db collection
          collection.find(function(err, res){
            res.toArray(function(err, realRes){
              console.log(realRes);
            });
          });          
   });
like image 191
Ebrahim Pasbani Avatar answered May 30 '26 14:05

Ebrahim Pasbani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!