开发者

MongoDB Database, order by a field which is a string field but with a number in it

开发者 https://www.devze.com 2023-04-03 21:35 出处:网络
I have a MongoDB and I nee开发者_C百科d to order by a field (id), but this field is a string field with a number in it.

I have a MongoDB and I nee开发者_C百科d to order by a field (id), but this field is a string field with a number in it.

Example:

   {
     "_id": ObjectId("4e60f8c2b1638e5479c8ba6f"),
     "id": "3188",
     "type": "P"
   }

The id field with value "3188" I need to order on that field as if it's an integer. Has MongoDB got some magic that it can do this?

Thanks!


Magick of mongodb not enough to sort string as integer ;)

So there is only one solution is to make int field from string field and sort on it.

0

精彩评论

暂无评论...
验证码 换一张
取 消