Cosmosdb保存的数据无法在门户中找到,但可以从azure-documentdb-spring-boot-starter中找到 [英] Cosmosdb Saved data cannot be found in portal but from azure-documentdb-spring-boot-starter

查看:118
本文介绍了Cosmosdb保存的数据无法在门户中找到,但可以从azure-documentdb-spring-boot-starter中找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目正在使用azure-documentdb-spring-boot-starter:0.2.0与cosmosdb进行交互:

My project is using azure-documentdb-spring-boot-starter:0.2.0 to interact with cosmosdb:

@Repository
public interface PingEasyRepo extends DocumentDbRepository<PingEasy, String> {
}


@Document(collection = "test")
public class PingEasy {
    @Id
    private String id;
    private String content;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

代码将运行,并且可以保存并查找全部.但是,当我转到azure门户和cosmosdb数据浏览器时,数据没有出现.打开浏览器工具时,看到带有

The code runs and can do save and findAll. But when I go to the azure portal and cosmosdb data explorer, the data not appeared. When I open browser tools, I see failed requests with

"500 Internal Server Error:对象引用未设置为对象的实例."和例外:

"500 Internal Server Error: Object reference not set to an instance of an object." and exceptions:

Uncaught TypeError: xhr.getResponseHeader is not a function
    at Object.DocumentClientFactory._shouldForceRetry (DocumentClientFactory.js?v=1.17.110.1:12)
    at HttpRequest.xhr.onreadystatechange (documentdbclient-1.14.0.js?v=1.17.110.1:3287)
    at HttpRequest._onAjaxError (Request.js?v=1.17.110.1:42)
    at i (jquery.min.js:2)
    at Object.fireWith [as rejectWith] (jquery.min.js:2)
    at y (jquery.min.js:4)
    at XMLHttpRequest.c (jquery.min.js:4)

以下是我用于自动创建cosmodb的脚本:

The following is the script I used to auto create my cosmodb:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "databaseAccountName": {
      "type": "string",
      "metadata": {
        "description": "The MongoDB database account name. Needs to be globally unique."
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "apiVersion": "2015-04-08",
      "type": "Microsoft.DocumentDB/databaseAccounts",
      "kind": "MongoDB",
      "name": "[parameters('databaseAccountName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "databaseAccountOfferType": "Standard",
        "name": "[parameters('databaseAccountName')]"
      }
    }
  ]
}

推荐答案

问题是,您正在创建一个MongoDB帐户,并使用了如您所链接的文章中所述的示例,该示例使用DocumentDB API写入数据.

The issue is that you are creating a MongoDB account and using a sample that writes data using the DocumentDB API, as stated in the article you linked.

Microsoft的Spring Boot Starter使开发人员能够使用Spring Boot应用程序,这些应用程序通过使用DocumentDB API轻松与Azure Cosmos DB集成.

Microsoft's Spring Boot Starter enables developers to use Spring Boot applications that easily integrate with Azure Cosmos DB by using DocumentDB APIs.

MongoDB帐户应与MongoDB客户端和应用程序一起使用,而不是与DocumentDB API客户端和应用程序一起使用.

MongoDB accounts are meant to be used with MongoDB clients and applications, not DocumentDB API clients and applications.

主要区别在于MongoDB的必需标识符字段为"_id",而DocumentDB/SQL帐户的必需标识符为"id".当您通过MongoDB客户端(应用程序或使用其中一个MongoDB SDK的代码)将文档写入MongoDB帐户时,驱动程序/客户端将确保您的文档具有必填的"_id"字段或自动生成一个.而且,当您使用DocumentDB API sdk/client和DocumentDB/SQL帐户时,sdk/client将自动生成必填的"id"字段.

The main difference is that MongoDB's required identifier field is "_id" while DocumentDB/SQL account's required identifier is "id". When you write documents to a MongoDB account through a MongoDB client (application or a code using one of the MongoDB SDKs), the driver/client makes sure your document has the required "_id" field or autogenerates one. And when you work with a DocumentDB API sdk/client and a DocumentDB/SQL account, the sdk/client will autogenerate the required "id" field.

门户网站使用MongoDB客户端读取MongoDB帐户中的文档,但是由于它们不是有效的MongoDB文档(没有必需的标识符)而无法读取文档.如果尝试使用自己编写的MongoDB应用程序读取文档,或者尝试使用Robomongo或Mongo Chef等MongoDB客户端读取文档,则会遇到相同的错误.

The Portal uses a MongoDB client to read the documents in a MongoDB account, but it is failing to read the documents because they are not valid MongoDB documents (don't have the required identifier). You will run into the same error if you try to read the documents with a MongoDB application coded by yourself or if you try to read that using a MongoDB client like Robomongo or Mongo Chef.

对于您的情况,如果要使用Spring Boot示例,则需要创建一个DocumentDB/SQL帐户.在文章的屏幕快照中,您可以看到如何创建一个SQL帐户.

In your case, if you want to use the Spring Boot sample, you need to create a DocumentDB/SQL account. In the screenshots of the article you can see how to create a SQL account.

希望这会有所帮助.

这篇关于Cosmosdb保存的数据无法在门户中找到,但可以从azure-documentdb-spring-boot-starter中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆