user3457759 user3457759 - 1 year ago 153
Javascript Question

How to use the hint operator from mongoDB in strongloop loopback?

I want to be able to use the hint operator from mongodb in Strongloop Loopback. I've been able to use this operator directly from mongodb but I haven't been able to use it from Strongloop Loopback. How can i use it in there?

Thanks in advance

Answer Source

You cannot use $hint operator directly in strongloop. However there is an alternate way to use it in strongloop.

Suppose your mongodb datasource in loopback name is mongodb.

//Here app is the loopback app object.
var mongoDb = app.dataSources.mongodb;
var mongoConnector = app.dataSources.mongodb.connector;

var promise = mongoConnector.collection("COLLECTION NAME").find( { $query: {}, $hint: { age : 1 } } )
    //Process data..