cnr-ibba / SMARTER-backend

SMARTER Backend API
https://webserver.ibba.cnr.it/smarter-api/docs/
GNU General Public License v3.0
0 stars 0 forks source link

:zap: limit variant locations in variants detail page #37

Open bunop opened 1 year ago

bunop commented 1 year ago

display only smarter coordinates in variant detail endpoint. This could be done by creating a new collection with only the information I need. This collection will be served by the endpoint.

bunop commented 2 months ago

this query can create a new collection with only the supported coordinates:

db.variantSheep.aggregate([
  { $unwind: "$locations" },
  {
    $match: {
      $or: [
        { "locations.version": "Oar_v4.0", "locations.imported_from": "SNPchiMp v.3" },
        { "locations.version": "Oar_v3.1", "locations.imported_from": "SNPchiMp v.3" }
      ]
    }
  },
  {
    $group: {
      _id: "$_id",
      chip_name: { $first: "$chip_name" },
      name: { $first: "$name" },
      sequence: { $first: "$sequence" },
      illumina_top: { $first: "$illumina_top" },
      sender: { $first: "$sender" },
      rs_id: { $first: "$rs_id" },
      locations: { $push: "$locations" },
      all_fields: { $mergeObjects: "$$ROOT" }
    }
  },
  {
    $replaceRoot: {
      newRoot: {
        $mergeObjects: [
          { $arrayToObject: { $objectToArray: "$all_fields" } },
          { locations: "$locations" }
        ]
      }
    }
  },
  { $limit: 2 }
], { allowDiskUse: true }).pretty()

Need to check if the fields non in the $group statement are preserved