从Cosmos DB查询时出现延续令牌问题

时间:2019-04-29 06:51:11

标签: python azure-cosmosdb azure-cosmosdb-sqlapi

从CosmosDB查询项目时,我遇到了延续问题。

我已经尝试过the following solution,但没有成功。即使我得到的令牌不是NULL,我也只能查询页面的前10个结果。

令牌的大小为10733 bytes,看起来像这样。

{"token":"+RID:gtQwAJ9KbavOAAAAAAAAAA==#RT:1#TRC:10#FPP:AggAAAAAAAAAAGoAAAAAKAAAAAAAAAAAAADCBc6AEoAGgAqADoASgAaACoAOgBKABoAKgA6AE4AHgAuAD4ASgAeACoAPgBOAB4ALgA+AE4AHgAqAD4ASgAeAC4APgBOAB4ALgA+AE4AIgA2AEYAFgAmADYARgAaACYAPgBKABYAKgA6AE4AHgAuAD4ATgAeAC4APgBOAB4ALgA+AE4AIgAuAD4ATgAeAC4APgBOACIAMgA+AFIAIgAyAD4AUgAmADIAQgAWACIALgBCABIAIgAyAEIAEgAiADIAQgAOACYANgBKAB4AJgA6AEYAGgAqADoATgAeAC4APgB....etc...etc","range":{"min":"","max":"05C1BF3FB3CFC0"}}

代码看起来像这样。函数QueryDocuments不起作用。相反,我不得不使用QueryItems

options = {} 
options['enableCrossPartitionQuery'] = True
options['maxItemCount'] = 10

 q = client.QueryItems(collection_link, query, options)
    results_1 = q._fetch_function(options)
    #this is a string representing a JSON object
    token = results_1[1]['x-ms-continuation']

    data = list(q._fetch_function({'maxItemCount':10,'enableCrossPartitionQuery':True, 'continuation':token}))

有解决方案吗?感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

请使用pydocumentdb软件包并参考下面的示例代码。

insert into [ManageSales].[dbo].[Inwestycje_test] (Id_KI, Nazwa)
select Id_KI, Nazwa
from [ManageSales].[dbo].[Inwestycje_test]
where id = 1 

输出:

enter image description here