Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My data structure in cosmosdb is next

   {
      "_id": {
      "$oid": "554f7dc4e4b03c257a33f75c"
      },
      .................
   }

and I need to sort collection by $oid field. How should I form my sql query?

Normal query SELECT TOP 10 * FROM collection c ORDER BY c._id.filedname not works if fieldname starts with $ like $oid.

I am using query explorer from azure portal.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

To use a special character, like $, you need to use bracket notation:

SELECT c._id FROM c
order by c._id["$oid"]

You can do this with each property in the hierarchy, so the following also works:

SELECT c._id FROM c
order by c["_id"]["$oid"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...