0

So I have this data model, based on a Facebook Insights API response, and you can assume is inserted as a document in a mongo collection.
My problem is: - The representation of the Insights data from FB is not the best, with keys that potentially could contain ".", or other chars not mongo friendly.

  • The queries I am trying to achieve, are sorted by some of the insights values:
    • Get all documents ranked by "Melbourne, VIC, Australia".

Based on the problem, my question then is:

  • Would you recommend transforming this documents into something more mongo friendly, and making the queries simpler? or
  • Would you leave this model representation and work around more complex queries

At the moment of editing this question, I have transformed Insights data representation but your opinion is welcomed!

Cheers!

    {
      "id": "155257214638229/insights/page_fans_city/lifetime", 
      "name": "page_fans_city", 
      "period": "lifetime", 
      "values": [
        {
          "value": {
            "Bogotá, Distrito Especial, Colombia": 206, 
            "São Paulo, Brazil": 102, 
            "Melbourne, VIC, Australia": 95, 
            "Cali, Valle del Cauca, Colombia": 76, 
            "Medellín, Antioquia, Colombia": 72, 
            "Bangalore, Karnataka, India": 39, 
            "Cartagena, Bolivar, Colombia": 38, 
            "Barranquilla, Atlantico, Colombia": 36, 
            "New Delhi, Delhi, India": 34, 
            "Ibagué, Tolima, Colombia": 32, 
            "Calcutta, West Bengal, India": 32, 
            "Bucaramanga, Santander, Colombia": 31, 
            "Sydney, NSW, Australia": 29, 
            "Mumbai, Maharashtra, India": 27, 
            "Lisbon, Lisboa, Portugal": 27, 
            "Mexico City, Distrito Federal, Mexico": 26, 
            "Neiva, Huila, Colombia": 23, 
            "Chennai, Tamil Nadu, India": 22, 
            "Hyderabad, Andhra Pradesh, India": 19, 
            "Chandigarh, India": 17, 
            "Pasto, Narino, Colombia": 17, 
            "Cúcuta, Norte de Santander, Colombia": 16, 
            "Santa Marta, Colombia": 16, 
            "Salvador, Bahia, Brazil": 16, 
            "Valledupar, Cesar, Colombia": 15, 
            "Palmira, Valle del Cauca, Colombia": 15, 
            "Montería, Cordoba, Colombia": 15, 
            "Rio de Janeiro, Brazil": 14, 
            "Lucknow, Uttar Pradesh, India": 14, 
            "Villavicencio, Meta, Colombia": 13, 
            "Belo Horizonte, Minas Gerais, Brazil": 13, 
            "Surat, Gujarat, India": 13, 
            "Ahmedabad, Gujarat, India": 13, 
            "Santiago, Region Metropolitana, Chile": 12, 
            "Brasília, Distrito Federal, Brazil": 12, 
            "Pereira, Risaralda, Colombia": 12, 
            "Jalandhar, Punjab, India": 11, 
            "Barrancabermeja, Santander, Colombia": 11, 
            "Tuluá, Valle del Cauca, Colombia": 11, 
            "Buenaventura, Valle del Cauca, Colombia": 11, 
            "Guadalajara, Jalisco, Mexico": 10, 
            "Goiânia, Goias, Brazil": 10, 
            "Adelaide, SA, Australia": 10, 
            "London, England, United Kingdom": 9, 
            "Armenia, Quindio, Colombia": 9
          }, 
          "end_time": "2015-02-19T08:00:00+0000"
        }, 
        {
          "value": {
            "Bogotá, Distrito Especial, Colombia": 207, 
            "São Paulo, Brazil": 103, 
            "Melbourne, VIC, Australia": 95, 
            "Cali, Valle del Cauca, Colombia": 75, 
            "Medellín, Antioquia, Colombia": 72, 
            "Bangalore, Karnataka, India": 40, 
            "Cartagena, Bolivar, Colombia": 38, 
            "Barranquilla, Atlantico, Colombia": 36, 
            "New Delhi, Delhi, India": 34, 
            "Ibagué, Tolima, Colombia": 32, 
            "Calcutta, West Bengal, India": 31, 
            "Bucaramanga, Santander, Colombia": 30, 
            "Sydney, NSW, Australia": 29, 
            "Lisbon, Lisboa, Portugal": 27, 
            "Mumbai, Maharashtra, India": 27, 
            "Mexico City, Distrito Federal, Mexico": 26, 
            "Neiva, Huila, Colombia": 24, 
            "Chennai, Tamil Nadu, India": 22, 
            "Hyderabad, Andhra Pradesh, India": 19, 
            "Chandigarh, India": 17, 
            "Pasto, Narino, Colombia": 17, 
            "Cúcuta, Norte de Santander, Colombia": 16, 
            "Santa Marta, Colombia": 16, 
            "Salvador, Bahia, Brazil": 16, 
            "Palmira, Valle del Cauca, Colombia": 15, 
            "Valledupar, Cesar, Colombia": 15, 
            "Montería, Cordoba, Colombia": 15, 
            "Rio de Janeiro, Brazil": 14, 
            "Lucknow, Uttar Pradesh, India": 14, 
            "Belo Horizonte, Minas Gerais, Brazil": 13, 
            "Surat, Gujarat, India": 13, 
            "Ahmedabad, Gujarat, India": 13, 
            "Villavicencio, Meta, Colombia": 13, 
            "Santiago, Region Metropolitana, Chile": 12, 
            "Brasília, Distrito Federal, Brazil": 12, 
            "Pereira, Risaralda, Colombia": 12, 
            "Jalandhar, Punjab, India": 11, 
            "Barrancabermeja, Santander, Colombia": 11, 
            "Tuluá, Valle del Cauca, Colombia": 11, 
            "Buenaventura, Valle del Cauca, Colombia": 11, 
            "Guadalajara, Jalisco, Mexico": 10, 
            "Goiânia, Goias, Brazil": 10, 
            "Adelaide, SA, Australia": 10, 
            "Dehra Dun, Uttarakhand, India": 9, 
            "San Luis Potosí, San Luis Potosi, Mexico": 9
          }, 
          "end_time": "2015-02-20T08:00:00+0000"
        }, 
        {
          "value": {
            "Bogotá, Distrito Especial, Colombia": 206, 
            "São Paulo, Brazil": 103, 
            "Melbourne, VIC, Australia": 95, 
            "Cali, Valle del Cauca, Colombia": 75, 
            "Medellín, Antioquia, Colombia": 72, 
            "Bangalore, Karnataka, India": 40, 
            "Cartagena, Bolivar, Colombia": 38, 
            "Barranquilla, Atlantico, Colombia": 36, 
            "New Delhi, Delhi, India": 34, 
            "Ibagué, Tolima, Colombia": 32, 
            "Calcutta, West Bengal, India": 31, 
            "Bucaramanga, Santander, Colombia": 31, 
            "Sydney, NSW, Australia": 29, 
            "Lisbon, Lisboa, Portugal": 27, 
            "Mumbai, Maharashtra, India": 27, 
            "Mexico City, Distrito Federal, Mexico": 26, 
            "Neiva, Huila, Colombia": 23, 
            "Chennai, Tamil Nadu, India": 22, 
            "Hyderabad, Andhra Pradesh, India": 19, 
            "Chandigarh, India": 17, 
            "Pasto, Narino, Colombia": 17, 
            "Santa Marta, Colombia": 16, 
            "Salvador, Bahia, Brazil": 16, 
            "Palmira, Valle del Cauca, Colombia": 15, 
            "Cúcuta, Norte de Santander, Colombia": 15, 
            "Rio de Janeiro, Brazil": 15, 
            "Valledupar, Cesar, Colombia": 15, 
            "Montería, Cordoba, Colombia": 15, 
            "Lucknow, Uttar Pradesh, India": 14, 
            "Belo Horizonte, Minas Gerais, Brazil": 13, 
            "Surat, Gujarat, India": 13, 
            "Villavicencio, Meta, Colombia": 13, 
            "Ahmedabad, Gujarat, India": 13, 
            "Santiago, Region Metropolitana, Chile": 12, 
            "Brasília, Distrito Federal, Brazil": 12, 
            "Pereira, Risaralda, Colombia": 12, 
            "Jalandhar, Punjab, India": 11, 
            "Barrancabermeja, Santander, Colombia": 11, 
            "Tuluá, Valle del Cauca, Colombia": 11, 
            "Buenaventura, Valle del Cauca, Colombia": 11, 
            "Guadalajara, Jalisco, Mexico": 10, 
            "Adelaide, SA, Australia": 10, 
            "Goiânia, Goias, Brazil": 10, 
            "Dehra Dun, Uttarakhand, India": 9, 
            "San Luis Potosí, San Luis Potosi, Mexico": 9
          }, 
          "end_time": "2015-02-21T08:00:00+0000"
        }
      ], 
      "title": "Lifetime Likes by City", 
      "description": "Lifetime: Aggregated Facebook location data, sorted by city, about the people who like your Page. (Unique Users)"
    }
Luchux
  • 803
  • 1
  • 7
  • 17
  • what is the problem you would like to solve, can you give some more insight? – Meteorpoly Feb 24 '15 at 03:54
  • I think this question will solve your problem http://stackoverflow.com/questions/25497150/mongodb-aggregate-by-field-exists – Neo-coder Feb 24 '15 at 04:52
  • I don't understand what your problem is. Could you clarify? Perhaps with example input and output? – wdberkeley Feb 24 '15 at 17:09
  • @Meteorpoly I edited the question, hope is more clear. basically if Insights data representation is the one to go for mongo, and the kind of query I am trying to do. Thanks! – Luchux Feb 24 '15 at 23:28
  • @Luchux , so your question is about data transformation/cleansing vs. complex queries? If this is the case than it depends on the amount of queries you have to do in your application against this, according to you, "non mongodb friendly" FB datasource. If it is only 1 or 2 occasions than I would go rather with a more complex query instead of introducing data transformation , but if it is more than once and mainly used for reporting & statistics I would go with a data transformation solution. If I still didn't understand your question please ignore my answer of course. – Meteorpoly Feb 25 '15 at 04:35

0 Answers0