[SERVER-24947] Need a type conversion mechanism for booleans, ISODates, ObjectID Created: 07/Jul/16 Updated: 06/Apr/23 Resolved: 06/Mar/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Adinoyi Omuya | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Duplicate | Votes: | 13 |
| Labels: | expression, usability | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Assigned Teams: |
Query
|
||||||||||||||||||||||||||||
| Sprint: | Query 12 (04/04/16), Query 13 (04/22/16), Query 15 (06/03/16) | ||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||
| Description |
|
Syntax
Examples
Notes
Errors
Each of these operators will have an equivalent $coerceTo operator that optionally accepts a default value in cases where the vanilla version would error. In cases where no default it supplied, it would return the default value for the target type. "false" for booleans, unix epoch for dates, and an empty string for object identifiers.
|
| Comments |
| Comment by Justin Seyster [ 06/Mar/18 ] | ||||||||||||||||||||||||||||||||||||
|
We now have $toInt, $toString, etc. conversion operators in aggregation ( | ||||||||||||||||||||||||||||||||||||
| Comment by Emre [X] [ 11/Nov/17 ] | ||||||||||||||||||||||||||||||||||||
|
I agree with Pavel Litvinenko. It would be nice to convert ObjectId to string in aggregation pipeline.
It's simple to sort and ready to create tree structure without any modification. | ||||||||||||||||||||||||||||||||||||
| Comment by Dissatisfied Former User [ 18/Jun/17 ] | ||||||||||||||||||||||||||||||||||||
|
As a cross-ticket referential integrity note, SERVER-29596 (projection of sub-components of an ObjectId) has an allowance for projecting an ObjectId to its hexadecimal string representation as well as projection of the date component as a date (amongst the other components); not a generic solution for general casting, but touches on this aspect of it. | ||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 08/Jun/17 ] | ||||||||||||||||||||||||||||||||||||
|
Date to string is already handled via existing $dateToString and date from string is a duplicate of | ||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 05/Jun/17 ] | ||||||||||||||||||||||||||||||||||||
|
Notes on original description:
I think there is strong reason to allow conversion to date from ObjectId, Bson timestamp and maybe longs (treated as bson timestamp/seconds since epoch). To boolean should also accept strings "true" and "false" and arguably any non-zero number should evaluate to true. Note that our own internal implicit conversion to boolean already works with all types. | ||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 31/May/17 ] | ||||||||||||||||||||||||||||||||||||
|
To and from string conversion is being tracked in the related/linked ticket | ||||||||||||||||||||||||||||||||||||
| Comment by Pavel Litvinenko [ 31/May/17 ] | ||||||||||||||||||||||||||||||||||||
|
Any plans for $toString operator? | ||||||||||||||||||||||||||||||||||||
| Comment by Pavel Bortnik [ 30/May/17 ] | ||||||||||||||||||||||||||||||||||||
|
Could you please throw some light on the progress of solving this issue? | ||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 07/Apr/17 ] | ||||||||||||||||||||||||||||||||||||
|
There is currently no way to convert ObjectId to another type inside aggregation pipeline. This ability is what this ticket is tracking (along with other types). | ||||||||||||||||||||||||||||||||||||
| Comment by Rafael da Silva Ferreira [X] [ 07/Apr/17 ] | ||||||||||||||||||||||||||||||||||||
|
#fact | ||||||||||||||||||||||||||||||||||||
| Comment by Pavel Litvinenko [ 06/Apr/17 ] | ||||||||||||||||||||||||||||||||||||
|
Unfortunately this didn't work because ObjectId() gives me new _id. | ||||||||||||||||||||||||||||||||||||
| Comment by Rafael da Silva Ferreira [X] [ 04/Apr/17 ] | ||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||
| Comment by Pavel Litvinenko [ 03/Apr/17 ] | ||||||||||||||||||||||||||||||||||||
|
Yes, i know about this method, but i mean a conversion of ObjectID inside of an aggregation pipeline. | ||||||||||||||||||||||||||||||||||||
| Comment by Rafael da Silva Ferreira [X] [ 03/Apr/17 ] | ||||||||||||||||||||||||||||||||||||
|
https://docs.mongodb.com/manual/reference/method/ObjectId.toString/ | ||||||||||||||||||||||||||||||||||||
| Comment by Pavel Litvinenko [ 01/Mar/17 ] | ||||||||||||||||||||||||||||||||||||
|
It would be nice to have ability to convert ObjectId to string. | ||||||||||||||||||||||||||||||||||||
| Comment by Rafael da Silva Ferreira [X] [ 30/Jan/17 ] | ||||||||||||||||||||||||||||||||||||
|
Any release date? |