如何在Node.js CosomosDB触发器上解密mongodb objectId [英] How to decrypt mongodb objectId on Nodejs CosomosDB Trigger
问题描述
我正在从自定义触发器中检索我的azure cosmosdb/mongodb文档到azure函数..但是我的objectId似乎已加密..如何获取正确的objectid ..
I am retrieving my azure cosmosdb/mongodb document from a custom trigger to azure functions.. But my objectId seems to be encrypted.. How to get the correct objectid..
例如 ObjectId("5df88e60d588f00c32a3c9ce")随] øŽ`Õˆð2£ÉÎ一起出现 或 ObjectId("5df88f92d588f00c32a3c9d1")随[strong>] ø’Õˆð2£ÉÑ
for example ObjectId("5df88e60d588f00c32a3c9ce") is coming as ]øŽ`Õˆð2£ÉÎ or ObjectId("5df88f92d588f00c32a3c9d1") is coming as ]ø’Õˆð2£ÉÑ
如果我输入] ø’Õˆð2£ÉÑ作为输入,是否可以在nodejs/python或任何脚本中检索objectid.
Is there a way to retrieve objectid in nodejs/python or any script if i give ]ø’Õˆð2£ÉÑ as input.
这是我在azure函数中使用的function.json
This is my function.json used in the azure function
{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases1",
"connectionStringSetting": "devcosmosdb_DOCUMENTDB",
"databaseName": "devcosmosdb",
"collectionName": "newCollection",
"createLeaseCollectionIfNotExists": "true"
}
]
}
这是我的nodejs代码.
This is my nodejs code..
module.exports = async function (context, documents) {
if (!!documents && documents.length > 0) {
context.log('Document Id: ', documents[0].id);
context.log(documents[0]);
}
}
这是我的输出,这是我没有正确获取对象ID的地方.
This is my output and this is where i am not getting the objectid properly..
2020-06-16T17:16:38Z [Information] Executing 'Functions.changeTrigger' (Reason='New changes on collection newCollection at 2020-06-16T17:16:38.2618864Z', Id=adc9556a-133f-4e85-b533-5574283a5a7d)
2020-06-16T17:16:38Z [Information] Document Id: NWRmODhkZGRkNTg4ZjAwYzMyYTNjOWNj
2020-06-16T17:16:38Z [Information] {
id: 'NWRmODhkZGRkNTg4ZjAwYzMyYTNjOWNj',
_rid: 'KEcnAO163B4EAAAAAAAAAA==',
_self: 'dbs/KEcnAA==/colls/KEcnAO163B4=/docs/KEcnAO163B4EAAAAAAAAAA==/',
_ts: 1592327797,
_etag: '"0000c1d2-0000-0300-0000-5ee8fe750000"',
'$t': 3,
'$v': {
_id: { '$t': 7, '$v': ']øÝÕð\f2£ÉÌ' },
name: { '$t': 2, '$v': 'myname' },
email: { '$t': 2, '$v': 'my email' },
},
_lsn: 537
}
推荐答案
请转到Azure门户检查文档的内容.我已经完成了一项测试,一切正常.
Please go to Azure portal to check the content of your document. I have done a test on my side, it just works fine.
这是我用来测试的文件.
Here is the document I used to test.
{
"id": "testid1",
"test1":"testvalue1",
"test2":{
"test21":"test21value",
"objectId":"5df88f92d588f00c32a3c9d1"
}
}
单击保存"按钮后,将触发该功能.
After clicking save button, the function will be triggered.
这是我的测试代码.
def main(documents: func.DocumentList) -> str:
if documents:
logging.info('Document id: %s', documents[0]['id'])
logging.info('%s',documents[0].to_json())
输出如下.
更新:
Azure函数cosmosdb触发器当前仅支持SQL API库.您还可以在设置"部分下找到该功能.
Currently only SQL API base is supported in Azure function cosmosdb trigger. You can also find the feature under Settings part.
URI应该类似于https://testbowman.documents.azure.com:443/
如果创建mongodb api cosmosdb帐户,将找不到添加到功能"功能. URI应该类似于https://tonycosmosdb.mongo.cosmos.azure.com:443/
If you create a mongodb api cosmosdb account, you won't find the 'add to function' feature. And the URI should be something like https://tonycosmosdb.mongo.cosmos.azure.com:443/
这篇关于如何在Node.js CosomosDB触发器上解密mongodb objectId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!