Can I use custom Sails query with padding?

I am using native

sails-mongo method to request a collection. I need to use native

Mongo to access some geospatial query capabilities.

I would like to use sails syntax populate

to include related models.

Is there a way to do this?

Here's an example of my existing code:

Trip.native(function(err, collection) {
    collection.find(
      {
        "locationTo": {
          "$near": {
            "$maxDistance": 80467.35439432222,
            "$geometry": {
              "type": "Point",
              "coordinates": [-117.133655, 32.720519]
            }
          }
        }
      }
    )
    .toArray(function(err, trips) {
      console.log("Trips nearby:", trips);
    });
});

      

Here is my ride model for reference.

var Trip = {
  attributes: {
    owner: {
      model: 'User'
    },
    title: 'string',
    addressFrom: 'string',
    locationFrom: 'json',  // geoJson
    dateTimeDepart: 'datetime',
    dateTimeArrive: 'datetime',
    dateTimeReturn: 'datetime',
    addressTo: 'string',
    locationTo: 'json',  // geoJson
    driver: {
      model: 'User'
    },
    status: {
      type: 'string',
      defaultsTo: 'PENDING'
    }  
  }
}

      

+3


source to share


2 answers


It would be helpful if you split the Trip model. If the field you want to fill is of type "collection" (not "array"), you should simply fill it.



Update: Ok, I misunderstood your question. There seems to be no way to check in immediately after being called native

. There's really little to do with the call native

regarding Waterline functions. I would suggest running another query (Waterline) after you have extracted locationTo

or filled in the fields yourself, since you only need to fill two of them (and this is also from the same model). I cannot think of anything that would be sufficient for one request.

+2


source


Thanks, I ended up doing it in two requests.

First, I create an array of match IDs using my own query.

var tripIdList = trips.map(function (trip) {
  return trip._id
});

      



Second, I am doing a normal search query using a list of ids. This is not a single request, but it works well. thanks for the help

Trip.find(filter)
  .where({id: tripIdList})
  .populate('driver')
  .exec(function (err, trips) {
     console.log("Trips:", trips);  
  }

      

+2


source







All Articles