Cosmos MongoDB集成的Azure功能无法保存 [英] Azure Function with Cosmos MongoDB integration not saving

查看:48
本文介绍了Cosmos MongoDB集成的Azure功能无法保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了带有Azure Cosmos DB(文档)输出的Azure功能. cosmos数据库配置为MongoDB. 并添加了以下简单代码来尝试添加新文档:

I have setup a Azure Function with a Azure Cosmos DB(document) output. The cosmos database is configured to be a MongoDB. And added the following simple code to try and add a new document:

module.exports = function (context, eventHubMessages) {
   context.bindings.document = {
   text : "Test data"
}   
context.done();
};

当我运行测试时,我获得了成功,但是当我尝试使用Studio 3T打开收藏集时,我得到了:

When i test run i get success, but when i try to open the the collection using Studio 3T i get:

Query failed with error code 1 and error message 'Unknown server error occurred when processing this request.'

当我使用相同的代码写入DocumentDB时,我获得了成功,并且可以在Azure中查看数据.您是否需要使用其他API将数据保存到mongoDB?

When i use the same code to write to a DocumentDB i get success and i can view data in Azure. Do you need to use a different API to save data to mongoDB?

推荐答案

DocumentDB输出绑定使用 DocumentDB API 来连接信息并将其保存在数据库中.但是您的数据库(按您的说法)正在使用 MongoDB API ,它们是不同的API(指向文档的链接).

The DocumentDB output binding is using the DocumentDB API to connect and save information in the database. But your database (from what you are saying) is using the MongoDB API, they are different APIs (links point to the docs).

您肯定知道,当您从MongoDB客户端(SDK或第三方客户端)连接到数据库时,MongoDB有一些要求(例如存在"_id"属性),但由于您通过DocumentDB API进行通信时,可能无法满足这些要求.

As you surely know, MongoDB has some requirements (like the existence of an "_id" attribute) that are covered when you connect to the database from a MongoDB client (either an SDK or a third-party client), but since you are communicating through the DocumentDB API, it's probably failing to fulfill those requirements.

您可能想尝试在函数中使用 Mongo驱动程序通过MongoDB API连接到您的Cosmos DB数据库.

You might want to try and use the Mongo driver in the function to connect to your Cosmos DB database through the MongoDB API.

这篇关于Cosmos MongoDB集成的Azure功能无法保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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