与 Cosmos MongoDB 集成的 Azure 函数未保存 [英] Azure Function with Cosmos MongoDB integration not saving

查看:15
本文介绍了与 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天全站免登陆