Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

azure - cosmos db sql query with non alphanumeric field name

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...