>> Hello there, and thank you very much for joining us
today in this new Azure Portal How To Video. Today we
learn how to use Azure Cosmos DB built-in notebooks.
And for that, we have Deborah Chen, who’s going to show
us how to do that. So, thank you very much for joining
us today, Deborah.
>> Hey, Leon. Super excited to be here. Let's dive right
into the demo.
>> Let's do it.
>> So, the easiest way to get started is from data
explorer. We can go to the gallery tab, and so we have
official samples written by the Cosmos DB team as well as
samples submitted by users in this public gallery.
We have notebooks written for both C# and Python and
our samples cover everything from getting started content
to general key concepts in Cosmos DB. We can also do
things like filter and search by tags. So, for example, if we
want to look at all the getting started content, we can find
one tag here, click on it, and see all the relevant
notebooks. Let's take a closer look at this notebook,.
the getting startedwith.NET SDK for SQL API.
We can view the notebook, which is great, but even better,
we can download it to my notebooks and get started with
it right away. Once it's
downloaded to my notebooks, it'll
show up here under my notebooks and we can start
running. As I mentioned earlier, in Cosmos DB we support
both C# and Python notebooks. This one is a C# notebook
And because it's C#, we're going to do everything we’d
expect for C# developers using Cosmos DB. For example,
we can start by bringing in relevant NuGet packages.
This sample happens to be one where we have some
sample IoT data that we're writing to our Cosmos DB
collection, and we’ll be using it to query and visualize the
data. So, this library that we just imported, Bogus, will be
very helpful here.
After importing the NuGet package, next we can use the
built-in Cosmos DB .NET SDK to create a new database and
container. If you notice here, this Cosmos DB client is
already aware of the context of the account so that
cosmos.endpoint, cosmos.key, so we don't even have to
hardcode every connection strings. It already knows what
the context of my account is. After I run the cell, we see
we have a couple lines that use the built-in SDK to create
a new database and a new container.
Then if we go back to our data section here, we see that
we actually were able to create the database and container.
In these next couple cells, we have some helper code to
represent the data that we’ll insert. This is the telemetry
event with some sensor data. So, this is just regular
C# class. We see we have some sensor data, S1, S2, S3
as well as some vehicle metadata.
And then these cells, we have some helper code that uses
that Bogus library imported to generate some sample data,
have it in a helper function, and call that function to insert
100 events into our container. So, that line, see right there?
There's the container.createitemsasync.
That container is
the same reference in the container we created earlier in
our database. So, once we
run that, if we actually go to look
at our items or documents, we see that the items were
indeed inserted based on that sample code.
Now that we have data inside our container, the next thing
we want to do is query and visualize it. Here we have
some sample code to run
the query to get top five results.
In this case, we’ll actually go ahead and change it to 100
results just to give us a bit more data to look at. And you
notice immediately that in addition to getting the results
in this nice grid view, we also provide some other options
to the right that are built-in visualizations to help you
analyze and visualize your data. So, for example, if I use
this built-in bar chart view, let's say I want to look at the
S1 metric for the vehicle type ore grouped by vehicle type,
I can quickly get an interactive bar chart that shows me all
the data I have for a quick view without writing any
additional code to build this visualization. So, in just a few
minutes, we're able to get started with Cosmos DB, run
in a sample notebook, generate data, and visualize it.
But what if you want to write your own notebook or share
that back to other members, other users of Cosmos DB?
If you want to write your own notebook, you can go to the
top right pane and create a new notebook. Once you select
new notebook, it'll show up in notebooks workspace and
here you can add your
content. I happen to have one I've
already written here called tips and tricks. This one
actually shows some Python SDK features and if I want to
share my notebooks that's available to any user of Cosmos
DB, I can publish it to our gallery. So, via the publish
gallery action, I'll give it a name, so this one will be called
demo tips and tricks. Description,
give us some tags, some
optional metadata here. And finally, to make it look nice, I
can provide a cover image. One nice thing we've done here
is in addition to letting you upload your own image. We
can also even take a screenshot of what your notebook
currently looks like. So, if we take a screenshot, it will
actually match what you're currently seeing on screen in
your notebooks. Once you hit publish, takes a second or
two, you'll be taken into my published work where you can
see this is the notebook I just published. And if you go to
the public gallery, you'll see here's a notebook I have
available to anyone who's viewing this public gallery in
Cosmos DB.
So, in conclusion, we've just seen how you can get
started with Cosmos DB's built-in notebooks and how to
share them with others. We welcome contributions and
look forward to seeing what you build with notebooks.
>> Thank you very much, Deborah. This was great.
And thanks every one for
watching. Please try this out and
let us know what you think. Leave us a comment in the
comment section, follow us on Twitter. Thanks for
watching and look forward to seeing you in the next video.
Bye now.