Skip to content

Complex query  #3661

Closed
Closed
@chlebta

Description

@chlebta

Sorry for posting this issue here but it's urgent :

I need help for creating an complexe query:

First here's a schema for my db :
img_1405

  • The friends model represent the friendship between two users.

  • Each user has a city

What I'm trying to achieve is to create function that take an userId as input and return list of cities Sorted by number of friends.

Here's my code until now

    function getCities(userId) {
    
      //This query allow to count number of friends in a given city 
      var innerQuery1 = new Parse.Query(Friends);
      innerQuery1. equalTo("user1", userId);
    
      var innerQuery2 = new Parse.Query(Friends);
      innerQuery2.equalTo("user2", userId);
    
      countFriendsQueryInCity = Parse.Query.or(innerQuery1, innerQuery2);
      countFriendsQueryInCity.equalTo("city", cityId)
      countFriendsQueryInCity.count({..})
    
      //This to get all cities
      var query = new Parse.Query(City);
     //Sort this query using the first one 
      query.find({})
      
    }

So the probleme is I can't figure a way way in parse or mongodb to join the two queries ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions