Cannot read property 'connector' of null in Loopback 3

148 Views Asked by At

i have problems when i trying to run raw mongodb queries on Loopback 3, here is my code :

MyModel.getDataSource().connector.connect(function(err, db) {
    var collection = db.collection('my_model');
    collection.aggregate([
        {$group : { _id: "$logid", "row":{"$first":"$$ROOT"}, count: { $sum: 1 } } },
        {$match: {_id :{ $ne : null } , count : {$gt: 1} } }, 
        {$sort: {count : -1} },
        {$project: {logid : "$_id", "_id" : 0, code:"$row.Code", id:"$row._id", model_type:"$row.model_type"} }     
      ], function(err, data) {
      if (err) return callback(err);
      return callback(null, data);
    });
  });

but when i running the program it return error on cmd like this :

 Cannot read property 'connector' of null

this is my datasource

"mongodb": {
"host": "127.0.0.1",
"port": 27017,
"database": "MyDatabase",
"name": "mongodb",
"connector": "mongodb",
"allowExtendedOperators": true }

thankyou in advance

0

There are 0 best solutions below