azure db 设置时区

Since we will sometimes require removing documents in Azure Cosmos DB, we’ll want to be able to specify the documents for removal. In some cases, this will be as simple as specifying a field for removal, such as removing one type of workout in our temporary database we’ve created. In other delete situations, we’ll want to remove if the value of the field isn’t what we expect – such as greater than what we want. This applies to updates as well – we may want to drill into a specific value range for an update. In this tip, we’ll look at using operators with strings, numeric types and dates.

由于有时有时需要删除Azure Cosmos DB中的文档,因此我们希望能够指定要删除的文档。 在某些情况下,这就像指定要删除的字段一样简单,例如在我们创建的临时数据库中删除一种锻炼类型。 在其他删除情况下,如果该字段的值不是我们期望的值,例如大于我们想要的值,我们将希望将其删除。 这也适用于更新–我们可能希望深入了解更新的特定值范围。 在本文中,我们将介绍如何将运算符与字符串,数字类型和日期一起使用。

Throughout this tip, we’ll be using the Shell in Cosmos DB and outputting fewer fields than our documents store so that we can see consolidate views. In addition, some of the queries won’t have corresponding images, but will have the document count that we expect along with the query to execute.

在整个技巧中,我们将在Cosmos DB中使用Shell,并且输出的字段少于文档存储的字段,以便我们可以看到合并视图。 此外,某些查询将没有相应的图像,但是将具有我们期望与查询一起执行的文档数。

使用运算符指定文档 (Using Operators to Specify Documents)

We’ve seen that we can remove or update records by using the unique key. We can also remove or update a group of records by using groups or by using operators. In the below query, we return all of the documents in our Azure Cosmos DB that are Treadmill Runs, displaying only the distance and time to show a consolidation of these documents. What if we wanted to remove all records that were over 3 miles? We could remove all the Treadmill Run types and add the two values that are exactly 3 back – but this would not be efficient if we had more documents.

我们已经看到,可以使用唯一键删除或更新记录。 我们还可以通过使用组或使用运算符来删除或更新一组记录。 在下面的查询中,我们返回Azure Cosmos DB中作为跑步机运行的所有文档,仅显示距离和时间以显示这些文档的合并。 如果我们想删除所有超过3英里的记录怎么办? 我们可以删除所有的“跑步机运行”类型,然后将恰好为3的两个值相加–但是,如果我们有更多的文档,这将是无效的。

db.Routines.find({"type": "Treadmill Run"},{_id:0, distance:1, time:1})

Here we’ll look at using operators. For this case, we’ll use a not equals operator ($ne) because our values for distance are strings. In Azure Cosmos DB, we should the appropriate string operators like we would use with SQL Server, .NET or other programming languages and because our distance values are strings (as opposed to numbers), so we’ll use the not equals. We’ll see that we follow a similar structure to our query so far where we specify the field and then open brackets with our operators. This is the SQL Server equivalent of WHERE Distance <> “3”. Since our numerical values for these documents are strings, let’s apply a math operator to our numerical values.

在这里,我们来看一下使用运算符。 对于这种情况,我们将使用不等于运算符( $ ne ),因为我们的distance值是字符串。 在Azure Cosmos DB中,我们应该像在SQL Server,.NET或其他编程语言中那样使用适当的字符串运算符,并且由于我们的距离值是字符串(而不是数字),因此我们将使用不等于。 到目前为止,我们将看到与查询类似的结构,其中指定了字段,然后用运算符将​​方括号括起来。 这与WHERE Distance <>“ 3”SQL Server等效。 由于这些文档的数值是字符串,因此我们将数学运算符应用于数值。

db.Routines.find({"type": "Treadmill Run", "distance": {$ne: "3"}},{_id:0, distance:1, time:1})

In the below query, we use the math operator greater than ($gt) to return our Jump Rope/Pushup Circuit exercises in our Azure Cosmos DB where we did more than 250 pushups. We’ll notice that our query for this follows the same syntax: we specify our field (Pushups) and use our greater than operator with the number we want returned above the value.

在下面的查询中,我们使用大于( $ gt )的数学运算符返回Azure Cosmos DB中的跳绳/俯卧撑电路练习,其中进行了250次以上的俯卧撑。 我们将注意到,对此查询的语法相同:我们指定字段(Pushups),并使用大于运算符,并将要返回的值大于该值。

使用比较运算符 (Using Comparative Operators)

With querying values in Azure Cosmos DB, we can use the below comparative operators that can be used similar to operators in SQL Server. The list covers the useful operators that we may require in common CRUD operations, especially in removals or updates.

通过查询Azure Cosmos DB中的值,我们可以使用以下比较运算符,这些运算符的用法类似于SQL Server中的运算符。 该列表涵盖了我们在常见CRUD操作中可能需要的有用运算符,尤其是在删除或更新中。

  • $eq: returns values that are equal to what’s provided $ eq :返回等于提供的值
  • $gt: returns values that are greater to what’s provided $ gt :返回大于所提供值的值
  • $gte: returns values that are greater than or equal to what’s provided $ gte :返回大于或等于提供的值
  • $in: returns values that are in what’s provided $ in :返回提供的值
  • $lt: returns values that are less than what’s provided $ lt :返回小于提供的值
  • $lte: returns values that are less than or equal to what’s provided $ lte :返回小于或等于提供的值
  • $ne: returns values that are not equal to what’s provided $ ne :返回不等于所提供值的值
  • $nin: returns values that are not in what’s provided $ nin :返回未提供的值

Without showing images of the results, let’s run the below queries in our Azure Cosmos DB and see what we get using each of these operators minus the ones we’ve already seen in the above examples with images. I highlight the number of results we should get each time.

在不显示结果图像的情况下,让我们在Azure Cosmos数据库中运行以下查询,并查看使用这些运算符获得的结果减去在上面示例中已使用图像看到的运算符。 我强调每次应获得的结果数。

 db.Routines.find({"type": "Treadmill Run", "distance": {$eq: "3"}},{_id:0, datetimeRoutine:0, type:0})

We use the equals operator ($eq) to find all the Treadmill Runs where the distance is equal to three miles and we get back 2 documents.

我们使用equals运算符( $ eq )查找距离等于3英里的所有跑步机运行,并获取2个文档。

db.Routines.find({"type": "Jump Rope/Pushup Circuit", "Pushups": {$gte: 290}},{_id:0, datetimeRoutine:0, type:0})

We use the greater than or equals to operator ($gte) to find all the Jump Rope/Pushup Circuit exercises where there were 290 pushups or more and get back 2 documents.

我们使用大于或等于运算符( $ gte )查找所有有290次以上俯卧撑的跳绳/俯卧撑电路练习,并取回2个文档。

db.Routines.find({"type": {$in: ["Treadmill Run","Endurance"]}},{_id:0, datetimeRoutine:0, type:0})

We use the in operators ($in) to find all the documents that are exercise types of Treadmill Runs or Endurance and we get back 6 documents. With Azure Cosmos DB, using the in or not in operators works like an array (for those familiar with object-oriented languages), where we’re looking for values in our array or not in our array. In the above query, we specify the values we’re seeking within the square brackets [] and because these values are a string, we wrap these values in quotation marks. We’ll use this same operator again, but this time apply the operator to numbers and we’ll notice that we remove the quotation marks because in Cosmos DB, these are not required for numerical values.

我们使用in运算符( $ in )查找所有属于“跑步机耐力运动”或“耐力运动”练习类型的文档,然后返回6个文档。 借助Azure Cosmos DB,使用in或not in运算符的工作方式就像一个数组(对于那些熟悉面向对象语言的人),我们在其中查找数组中的值或不在数组中查找值。 在上面的查询中,我们在方括号[]中指定要查找的值,并且由于这些值是字符串,因此将这些值用引号引起来。 我们将再次使用相同的运算符,但是这次将运算符应用于数字,并且我们会注意到我们删除了引号,因为在Cosmos DB中,数字值不是必需的。

db.Routines.find({"Pushups": {$in: [250,290]}},{_id:0, datetimeRoutine:0, type:0})

This numerical in query returns 2 documents.

查询中的该数字返回2个文档。

db.Routines.find({"type": "Jump Rope/Pushup Circuit", "Pushups": {$lt: 290}},{_id:0, datetimeRoutine:0, type:0})

We use the less than operator ($lt) to find all Jump Rope/Pushup Circuit exercises where the pushups are less than 290 and we get back 2 documents.

我们使用小于运算符( $ lt )查找俯卧撑小于290的所有跳绳/俯卧撑电路练习,并返回2个文档。

db.Routines.find({"type": "Jump Rope/Pushup Circuit", "Pushups": {$lte: 290}},{_id:0, datetimeRoutine:0, type:0})

We use the less than or equals to operator ($lt) to find all Jump Rope/Pushup Circuit exercises where the pushups are less than or equal to 290 and we get back 3 documents.

我们使用小于或等于运算符( $ lt )查找俯卧撑小于或等于290的所有跳绳/俯卧撑电路练习,并返回3个文档。

db.Routines.find({"type": "Treadmill Run", "distance": {$nin: ["3","3.1"]}},{_id:0, datetimeRoutine:0, type:0})

Similar to the in operator ($in) which uses an array in Azure Cosmos DB, we use the not in operator ($nin) to get all the Treadmill Runs where the distance is not in 3 or 3.1 miles. We get back 1 document. Identical to the in operator, we must pass in the appropriate type for our array – string values for strings and numerical values for numbers. For dates, we format our in or not in like strings, as we see in the below query which returns 7 documents.

与在Azure Cosmos DB中使用数组的in运算符( $ in )相似,我们使用not in运算符( $ nin )获取距离不在3或3.1英里之内的所有跑步机运行。 我们拿回1个文件。 与in运算符相同,我们必须为数组传递适当的类型-字符串的字符串值和数字的数值。 对于日期,我们格式化我们 不在家像琴弦,因为我们在下面的查询返回7个文件看。

db.Routines.find({"datetimeRoutine": {$nin: ["2017-01-10 4:00AM","2017-01-11 4:00AM","2017-01-02 4:00AM"]}},{_id:0, datetimeRoutine:0, type:0})

通过集删除文档和添加对象 (Removing Documents By Sets and Adding Objects)

For our Cosmos DB, suppose that our client wanted to set Treadmill runs at 3 miles only, regardless of whether it exceeded that value. We could run an update statement, but for this example we will remove these documents in a set – removing two documents using our operator not equal ($ne). However, we want to keep these values in our database, so we’ll re-add them back with the same details except the distance is 3 miles instead of the more detailed values. Rather than add them as we’ve done in the previous tip, we’ll first store the documents in objects that we’ll add later.

对于我们的Cosmos DB,假设我们的客户希望将跑步机的行驶距离设置为仅3英里,而不管其是否超过该值。 我们可以运行一条update语句,但是在本示例中,我们将删除一组文档–使用我们的运算符not equal( $ ne )删除两个文档。 但是,我们希望将这些值保留在数据库中,因此我们将使用相同的详细信息将它们重新添加回去,只是距离为3英里而不是更详细的值。 与其像我们在上一个技巧中所做的那样添加它们,不如将它们首先存储在稍后将添加的对象中。

var doc1 = {“datetimeRoutine” : “2017-01-10 4:00AM”, “type” : “Treadmill Run”, “distance” : “3”, “time” : “30”}
doc1
var doc2 = {“datetimeRoutine” : “2017-01-13 4:00AM”, “type” : “Treadmill Run”, “distance” : “3”, “time” : “30”}

From here, we remove the documents in our Azure Cosmos DB that have distances not equal to 3 miles and validate the removals with a query to return the 2 documents remaining.

从这里,我们删除Azure Cosmos数据库中距离不等于3英里的文档,并通过查询返回剩余的2个文档来验证删除。

Db.Routines.remove({“type”: “Treadmill Run”, “distance”: {$ne: “3”}})
db.Routines.find({“type”: “Treadmill Run”},{_id:0, datetimeRoutine:0, type:0})

Now, we’ll insert our two documents that we stored in two different objects – doc1 and doc2. Notice that we simply have to pass in the object with the insert statement and the record is added.

现在,我们将插入存储在两个不同对象(doc1和doc2)中的两个文档。 注意,我们只需要使用insert语句传入对象,然后添加记录。

When we work with documents in Azure Cosmos DB, just like with MongoDB, we will be working with objects that have documents or arrays of documents. As we see, we won’t have always specify the fields – though there may be CRUD operations where we do because of a change or removal. We will generally be getting an object made of a document or set of documents or adding a document or a set of documents. For instance, suppose that we wanted to store details of a workout in an object from a query – we can apply the above logic and save a document to and object with a query:

与在MongoDB中一样,当我们在Azure Cosmos DB中使用文档时,我们将使用具有文档或文档数组的对象。 如我们所见,虽然由于更改或删除而可能需要执行CRUD操作,但我们不一定总是指定字段。 通常,我们将获得由一个文档或一组文档构成的对象,或者添加一个文档或一组文档。 例如,假设我们想通过查询将锻炼的详细信息存储在对象中–我们可以应用以上逻辑,并通过查询将文档保存到对象:

var nextDay = db.Routines.find({"datetimeRoutine" : "2017-01-02 4:00AM"}, {_id:0, datetimeRoutine: 0})
nextDay

We can apply this further to multiple documents – a collection of documents within one object:

我们可以将其进一步应用于多个文档–一个对象内的一组文档:

var allCardio = db.Routines.find({"type": {$in: ["Treadmill Run","Endurance"]}},{_id:0, datetimeRoutine:0, type:0})
allCardio

This becomes useful in many contexts with Cosmos DB, as we can re-use the object we’ve created if we need the documents for multiple purposes. In addition, we may want to transform the data for reports or for feeding to other back-ends and these objects allow us to do further manipulation without affecting the underlying data in our database.

在Cosmos DB的许多情况下,这变得很有用,因为如果我们出于多种目的需要文档,则可以重新使用创建的对象。 此外,我们可能希望转换数据以用于报告或用于其他后端,并且这些对象使我们能够做进一步的操作而不会影响数据库中的基础数据。

结论 (Conclusion)

Using operators can save us significant time when we remove documents or run updates on documents. Some updates may be applied relative to a field filter, but we may need to drill further into a field, like we saw with removing and re-adding our Treadmill runs. Azure Cosmos DB provides us with many standard operators we use with back-ends like SQL Server, which allow us to execute our CRUD operations against multiple documents at a time. In addition, we can create documents and save them to objects, or save query results in objects, from one document to multiple documents in the same object.

当我们删除文档或对文档运行更新时,使用运算符可以为我们节省大量时间。 可能会相对于字段过滤器进行一些更新,但是我们可能需要进一步深入到字段中,就像我们看到的删除并重新添加跑步机运行一样。 Azure Cosmos DB为我们提供了许多用于后端(如SQL Server)的标准运算符,使我们可以一次对多个文档执行CRUD操作。 另外,我们可以创建文档并将其保存到对象,或将查询结果保存在对象中,从一个文档到同一对象中的多个文档。

目录 (Table of contents)

Getting Started with Azure Cosmos DB
Updating and Querying Details in Azure Cosmos DB
Applying Field Operators and Objects in Azure Cosmos DB
Getting Started with Subdocuments in Azure Cosmos DB
Azure Cosmos DB入门
在Azure Cosmos DB中更新和查询详细信息
在Azure Cosmos DB中应用字段运算符和对象
Azure Cosmos DB中的子文档入门

翻译自: https://www.sqlshack.com/applying-field-operators-and-objects-in-azure-cosmos-db/

azure db 设置时区

azure db 设置时区_在Azure Cosmos DB中应用字段运算符和对象相关推荐

  1. azure db 设置时区_关于Azure Cosmos DB(以前称为DocumentDB)的8件事

    azure db 设置时区 介绍 (Introduction) Azure Cosmos DB is a low-latency, high throughput, globally distribu ...

  2. azure db 设置时区_使用Azure Cosmos DB开始您的旅程

    azure db 设置时区 In this article, we will discuss why we need to use Azure Cosmos DB and how to configu ...

  3. azure db 设置时区_将数据迁移到Azure Cosmos DB

    azure db 设置时区 In the previous article, Start your journey with Azure Cosmos DB, we provided you with ...

  4. mysql中如何设置时区_如何设置MySQL的时区?

    我认为这可能是有用的: 有三个位置可以在MySQL中设置时区: 在[mysqld]部分中的"my.cnf"文件中default-time-zone='+00:00' @global ...

  5. php 设置时区_为什么没有 Asia/Beijing 时区?

    在设置系统时间.开发PHP和Java程序(例如用JDBC访问MySQL数据库)的时候,有时需要选择本地时区.通常,时区列表中和中国有关的共有六个本地时区:Asia/Chongqing.Asia/Sha ...

  6. java calendar 设置时区_详解Java时区处理之Date,Calendar,TimeZone,SimpleDateFormat

    一.概述 1.问题描述 使用Java处理时间时,我们可能会经常发现时间不对,比如相差8个小时等等,其真实原因便是TimeZone.只有正确合理的运用TimeZone,才能保证系统时间无论何时都是准确的 ...

  7. java calendar 设置时区_设置calendar时区

    iOS - Swift NSTimeZone时区 前言 public class NSTimeZone : NSObject, NSCopying, NSSecureCoding NSTimeZone ...

  8. Mysql时区设置最佳实践,mysql设置时区_修改MySQL时区设置的方法

    摘要 腾兴网为您分享:修改MySQL时区设置的方法,一直播,一点开,小猿口算,汤圆等软件知识,以及都优乐,daysmatter,乐学高考app,随缘漂流瓶,虚拟软件,平安知鸟,智能证件照app,新概念 ...

  9. mysql6.0设置时区_关于Mysql6.0+的时区错乱问题

    如果使用mysql6.0+的JDBC驱动版本的时候,有时候会出现程序时间与数据库时间相差很多个小时; 1.如果以北京时间为例,相差8个小时的情况一般是你在连接jdbc的url中没有标明system_t ...

最新文章

  1. chrome使用技巧(看了定不让你失望)
  2. socks5   代理
  3. hadoop 2.2 本地库编译
  4. php删除两端,php删除字符串末尾子字符,删除开始字符,删除两端字符的示例代码...
  5. 996和被辞退,二选一
  6. linux mysql 释放x锁_MySQL 加锁处理分析-转载
  7. 数据挖掘:实用案例分析 下载_【实用干货】17 种服装印花工艺(图文案例分析)...
  8. SpringCloud学习之网关gateway
  9. 输入这个命令之后,FinalShell连接不上地推主机了
  10. AStar寻路2-性能优化
  11. c语言如何调用三个子程序,哪位师傅知道51单片机怎样编写子程序?C语言的。在主程序里调...
  12. poj 1860 bellman 求正环
  13. poj 1062 昂贵的聘礼 最短路
  14. Linux之centos7 VMware安装教程
  15. CentOS下Red5安装
  16. 文字转语音(Python pyttsx3)
  17. 什么是激励函数?(代码+详细注释)
  18. oracle迁移价格,oracle 迁移的一般方法
  19. 用html和css实现字体发光效果
  20. The Nicest Word(io优化)

热门文章

  1. fir1截止频率计算_数字信号处理 实验五:FIR数字滤波器设计与软件实现
  2. c语言屏蔽按键,VC实现让关闭按钮成灰色不可用的方法
  3. Windows Live Writer
  4. Django中@login_required用法简介
  5. java知识点(记录用)
  6. JAVA中GridBagLayout布局管理器应用详解
  7. 垃圾,奇慢 ORACLE ODAC
  8. RN性能优化以及事件监听
  9. LeetCode(257)——二叉树的所有路径(JavaScript)
  10. (进阶)LeetCode(9)——回文数(JavaScript)