How can we improve Azure Cosmos DB?

Query for Fields not defined

Query documents that don't have fields defined?
Select * from docs d where d.Foo = Undefined

This would be useful for querying for past versions of documents that didn't have certain fields.

1 vote
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Tom Tucker shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    3 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Ruslan commented  ·   ·  Flag as inappropriate

        For anyone who wants a Linq solution, it's: query.Where(d => !d.Foo.IsDefined()). To get the IsDefined extension method, you need to add "using Microsoft.Azure.Documents.SystemFunctions"

      • Jay commented  ·   ·  Flag as inappropriate

        You can try the coalesce operator (double question mark ??). For example, to check if a Foo is undefined/null/false
        query.where(d.Foo == null || !(d.Foo ?? false))

      • Tom Tucker commented  ·   ·  Flag as inappropriate

        Response from @DocuemntDB on twitter
        we will be adding ISDEFINED to the SQL Query Grammar at some point. ISUNDEFINED will be the functional equivalent of that UDF

        Use temporary user defined function to solve problem

        function isUndefined(input, property) { return (typeof input[property] === 'undefined'); }

      Feedback and Knowledge Base