Join Chander Dhall for an in-depth discussion in this video Query with equality and inequality, part of Cosmos DB Developer Deep Dive.
- [Instructor] Now there's a lot of different operators we can use and a lot of times, what you could also do is use AND. And in this case, if the c.Name is Flextor and then we have Category_Code that's web, only then you're going to get a result back. And we can do this everywhere. We can also change this to AND and the way you make AND work here is like this. Now this might not be a query that might give us a result back so let's see if we get anything back.
I'm going to add a break point here and do F5. So as you can see the count is zero, but the query is perfectly valid and the reason it's zero is because when we have the name Flextor, the Category_Code wasn't web. It was something else. So let's go to the portal and grab something that we know is going to work so we have Omnidrive and then we have the Category_Code that's network_hosting. Back to Visual Studio and change our query and press F5 and we have count one.
This is exactly what we were expecting. We've got the id and we've got the name. Another thing you could do is you can come in here and say, "Well, I want it, but the name should be Omnidrive "and the Category_Code cannot actually be network_hosting." So in this case, we might not get any data back so let's try web and do F5. So we see that we do get id which is a name Omnidrive 'cause that was probably the only name in the database, but we are sure that we are not going to get it if it the Category_Code is not web.
So it's like I want something with name Omnidrive, but without the Category_Code of web. And if you were to do the same thing here, you would do not equals and in this case, you would do something like what we do in SQL which is this particular less than and greater than sign together. Let's add a break point here, formatting the code with just Control + K + D so we can see that Console.ReadLine is an independent line and do an F5 and we should get the same exact result in all the three queries.
We have a count one. In this case, we actually don't have a count one and we'll see why 'cause we have a different name so let's fix that name real quick. Now we should get the same exact result in all the three queries, except here we're selecting an id and in this case we're selecting a category id and same for number three. F5.
So we have companies count one. We've got Omnidrive, same result here. We have Omnidrive with Category_Code network_hosting and that's exactly what we have here.
- Data import scenarios
- Creating a database
- Creating a partitioned collection
- Data manipulation
- Importing documents with a stored procedure
- User-defined functions
- Excluding indexing at a document level
- Range indexing on strings
- Querying with SQL parameters
- Range operations