-3

I'm using Cosmos DB in Azure. I recently changed the schema to add more information. However, I'm confused because Cosmos uses SQL to query the database. Further, it seems I can't query based on the new schema because I receive the following error messsage:

 Message: {"errors":[{"severity":"Error","location":{"start":22,"end":29},"code":"SC2001","message":"Identifier 'comment' could not be resolved."}]}

So I'm wondering is it possible to disable schema validation so I can query on the new comment attribute, without getting this error message.

Further, I'm confused how Cosmos DB can be considered a NoSQL database if it behaves much the same as MySQL.

Edit: The query I am using is

SELECT * FROM c
WHERE comment = ""
David Makogon
  • 69,407
  • 21
  • 141
  • 189
Timothy Pulliam
  • 132
  • 1
  • 9
  • 25
  • Can you share which is the query you are attempting to execute? It looks like the error is not the schema but how the query is written – Matias Quaranta Feb 10 '22 at 17:29
  • @MatiasQuaranta I have added the query I am using – Timothy Pulliam Feb 10 '22 at 17:31
  • 1
    FYI your error is a typo (you need `c.comment` and not `comment`). As for your comparison of Cosmos DB to MySQL, and how Cosmos DB could be considered "NoSQL" - NoSQL has nothing to do with a specific query language. It's about non-relational data modeling (and even within that definition, there are many types of NoSQL databases, and then many "brands" of each type of database). NoSQL is an umbrella term for a category of databases. One last thing: Cosmos DB does not behave the same way as MySQL. – David Makogon Feb 10 '22 at 19:59

1 Answers1

2

The error is not related to the schema, the error is saying your query is incorrectly written.

Following the official documentation (for example, https://learn.microsoft.com/azure/cosmos-db/sql/sql-query-getting-started#query-the-json-items)

The query should be:

SELECT * FROM c
WHERE c.comment = ""

Keep in mind that that query is not checking for documents that do not have the comment property, it's basically filtering documents that do have the comment property with an empty string value.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47