My use case is to get all datatype of _id present in a collection. I use these _id types in further downstream processes. This is primarily required as MongoDB doesn't itself return all datatypes with a $gte/$lte operation and only returns the values of the datatype mentioned. I'd need the datatypes of _id to achieve the necessary parallelizations. Currently, I'm using a DB aggregation call to the collection:
db.collection.aggregate({ $group : { _id : {$type:"$_id"}} } )
However, this is an extremely expensive call especially when the size of the collection is in the billions. I was hoping that since there is no internal comparator in MongoDB to distinguish between, say an objectID and a numeric type, I should be able to get the datatypes of _id present in some metadata ideally. Is there any such way to get this information or perhaps a faster way to get all datatypes of _id in a collection?