chnage collection column datatype

37 views
Skip to first unread message

Bhanu Busi

unread,
Sep 19, 2018, 1:55:27 AM9/19/18
to mongod...@googlegroups.com
Hi Guys,

how to change column datatype double datatype to string datatype in  mongodb
Thanks,
Bhanu.





Wan Bachtiar

unread,
Sep 20, 2018, 9:18:59 PM9/20/18
to mongodb-user

how to change column datatype

Hi Bhanu,

Could you elaborate the question with more information and an example ?
Is this from a mongo shell or using a specific MongoDB driver ? If so, which language ?

If you just would like to convert data types in MongoDB collection, you could try to use $convert aggregation pipeline operator (since MongoDB v4.0).

For example:

> db.collection.aggregate([{"$addFields":{"b":{"$convert":{"input":"$a", "to":"string"}}}}])

{
    "_id": ObjectId("..."),
    "a": NumberDecimal("1.01234567890123"),
    "b": "1.01234567890123"
}

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages