cosmosDB 无法读取 trimSlashes 处未定义的 属性 'replace'

cosmosDB Cannot read property 'replace' of undefined at trimSlashes

我遇到了一个问题,我尝试向 cosmosDB 创建一个项目,但每当我尝试保存一个项目时,它都会抱怨 trimSlashes 函数。

语言:Node.js 10.x.x Npm 模块:“@azure/cosmos”:“^3.7.4”,

错误:

{ TypeError: Cannot read property 'replace' of undefined
    at trimSlashes (D:\home\site\wwwroot\node_modules\@azure\cosmos\dist\index.js:324:23)
    at D:\home\site\wwwroot\node_modules\@azure\cosmos\dist\index.js:7002:40
    at Generator.next (<anonymous>)
    at D:\home\site\wwwroot\node_modules\@azure\cosmos\node_modules\tslib\tslib.js:114:75
    at new Promise (<anonymous>)
    at Object.__awaiter (D:\home\site\wwwroot\node_modules\@azure\cosmos\node_modules\tslib\tslib.js:110:16)
    at httpRequest (D:\home\site\wwwroot\node_modules\@azure\cosmos\dist\index.js:6979:22)
    at D:\home\site\wwwroot\node_modules\@azure\cosmos\dist\index.js:6375:24
    at Generator.next (<anonymous>)
    at D:\home\site\wwwroot\node_modules\@azure\cosmos\node_modules\tslib\tslib.js:114:75
  headers:
   { 'x-ms-throttle-retry-count': 0,
     'x-ms-throttle-retry-wait-time-ms': 0 } }

输入:

{ id: '1',
  subEntries: 'a',
  errorName: 'b',
  errorMessage: 'c',
  errorCode: 'd',
  errorStack: 'e' }

 { id: '1'}

代码:

async function saveToCosmosDB(error) {
    const client = new CosmosClient({ cosmosDBEndpoint, cosmosDBKey });
    const database = client.database(cosmosDBDatabase);
    let container = database.container(cosmosDBContainer);
    const res = await container.items.create(error);
    return res
}

现在我也尝试了不同的输入,其中我只在输入中传递了 ID,但由于某种原因,所有输入都失败了。尝试按照上面的示例定义分区键,也尝试过不定义分区键,似乎所有这些都以相同的错误告终,此时我不知道是什么导致了它。 还查看了教程和官方文档。

例如:https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-nodejs-application 例如:https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-nodejs-samples

感谢任何帮助推进此工作的人。

编辑

我深入研究了 node_module 库,似乎这个错误发生在包试图连接到数据库时,这真的很奇怪,因为我正在使用的 cosmos DB 是 public,并且对 NSG 的 azure 函数也没有限制。将 post 一个 update/solution 一旦找到一个

长话短说,错误是 syntax/naming 错误: 当我创建新的 CosmosClient 时重新命名传递的变量将解决问题。在我看来,SDK 不抛出有意义的错误是非常愚蠢的。我 运行 进入的 SDK 也存在其他问题,这些问题与 partitionKeyDefinition 问题有关。但是这个帖子从我这边算解决了。

async function saveToCosmosDB(error) {
    const client = new CosmosClient({ endpoint, key});
    const database = client.database(cosmosDBDatabase);
    let container = database.container(cosmosDBContainer);
    const res = await container.items.create(error);
    return res
}