Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用NodeJS从CosmosDB集合中删除没有分区键的文档_Node.js_Azure_Azure Cosmosdb - Fatal编程技术网

Node.js 使用NodeJS从CosmosDB集合中删除没有分区键的文档

Node.js 使用NodeJS从CosmosDB集合中删除没有分区键的文档,node.js,azure,azure-cosmosdb,Node.js,Azure,Azure Cosmosdb,以下是我用来删除文档的代码: const CosmosDbClient = require('documentdb').DocumentClient let client = new CosmosDbClient(URL, { masterKey: KEY }) client.deleteDocument(docUrl, { partitionKey: partitionKeys }, (err) => { if (err) { throw er

以下是我用来删除文档的代码:

const CosmosDbClient = require('documentdb').DocumentClient
let client = new CosmosDbClient(URL, {
    masterKey: KEY
  })
client.deleteDocument(docUrl, {
    partitionKey: partitionKeys
  }, (err) => {
    if (err) {
      throw err
    } else {
      console.log('DELETED document ' + docUrl)
    }
  })
它适用于具有分区键的集合。对于这种情况,我将
['myPartitionKey']
传递给
partitionKeys
变量。但我对不使用分区的集合感到迷茫

azure documentdb node和vscode cosmosdb中的许多问题和PRs相互引用

我还不明白的是,为什么不修复documentdb npm包存储库,而是在VSCOSMOSDB中进行修复

问题提到了问题,并分享了可能的解决方案

尽管我尝试传递
null、未定义和{}
,但没有任何效果。我得到:


提供的分区键与集合中的定义不对应,或者与文档中指定的分区键字段值不匹配。

我为您做了两项测试。我的documentdb npm软件包版本是
1.14.2

第一种情况:要删除分区集合中未定义分区键的文档

示例文档:

删除代码:

第二种情况:要删除非分区集合中未定义分区键的文档

示例文档:

删除代码:


希望对您有所帮助。

您的集合是分区集合,而您只是没有为要删除的文档提供分区键值,还是集合不是分区集合?哪一个是这样的?@GauravMantri我的收藏很小。我不使用分区,然后我认为将
{}
作为第二个参数传递应该是可行的。这就是我们在代码中使用的方式
client.deleteDocument(docUrl,{},(err)=>{})
。在您的评论之后,我现在再次尝试了它。它返回错误以及上面问题中提到的消息。我的documentdb npm软件包版本是
1.14.5
@FarrukhNormuradov Hi,现在有更新吗?
var config = require("./config");

var docUrl= "dbs/db/colls/coll/docs/3"

const CosmosDbClient = require('documentdb').DocumentClient
let client = new CosmosDbClient(config.endpoint, {
    masterKey: config.primaryKey
  })
client.deleteDocument(docUrl, {
    partitionKey: {}
  }, (err) => {
    if (err) {
      console.log(err)
      throw err
    } else {
      console.log('DELETED document ' + docUrl)
    }
  })
var config = require("./config");

var docUrl= "dbs/db/colls/import/docs/3"

const CosmosDbClient = require('documentdb').DocumentClient
let client = new CosmosDbClient(config.endpoint, {
    masterKey: config.primaryKey
  })
client.deleteDocument(docUrl, {
  }, (err) => {
    if (err) {
      console.log(err)
      throw err
    } else {
      console.log('DELETED document ' + docUrl)
    }
  })