Convert String to Int on AWS DocumentDB
Asked Answered
M

1

7

I am currently trying to write a metabase question off AWS Document DB and I am running into an issue where I need to convert a string to an integer. Unfortunately, it seems like aws documentdb does not support $toInt and I am not sure how to get around it. Here is the query:

[
    {"$match": { 
        "metaData.fileSize" : {"$exists": true}
    }},
    {"$project": { 
        "file_size" : "$metaData.fileSize",
        "timestamp": 1,
        "past7Days": 
        { "$subtract": 
                [ ISODate(), 604800000]
        }
    }},
    {"$project": { 
        "file_size" : 1,
        "timestamp": 1,
        "dayofweek": {"$dayOfWeek":["$timestamp"]},
        "past7DaysComp": 
        { "$subtract": 
                [ "$timestamp", "$past7Days"]
        }
    }},
    {"$group" : 
            {   
                "_id" : {"dayofweek" : "$dayofweek"},
                "size": {"$avg" : "$file_size"}
            }
    }
]

The group returns nothing for size since it is not of a numeric type. Any ideas how to convert file_size to integer or double or float?

Monotheism answered 26/5, 2020 at 22:2 Comment(1)
DocumentDB does not support $toInt. You can try this out programmatically: Example: db.collectionName.find().forEach(function(data) { db.collectionName.update({ "_id": data._id, "moop": data.moop }, { "$set": { "PartnerID": parseInt(data.PartnerID) } }); })Manfred
G
1

As of 2023-11-11, the $convert and below similar conversion aggregation APIs have become available on AWS documentDB on v4.0+, according to the official doc from AWS

  • $convert
  • $toBool
  • $toDate
  • $toDecimal
  • $toDouble
  • $toInt
  • $toLong
  • $toObjectId
  • $toString
Goldsworthy answered 12/11, 2023 at 3:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.