繁体   English   中英

使用Mule连接MongoDB

[英]using Mule to connect MongoDB

我使用Mule获取了一些SQLServer数据库表,现在我需要在mongoDB中创建一个集合。

我能够创建成功的连接,但无法在MongoDB中创建集合。

下面是我正在使用的XML

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">
<db:generic-config name="MicrosoftSQLServerDB"         url="jdbc:sqlserver://localhost:1433;DatabaseName=TESTNAV;user=sa;password=xxxxx" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" doc:name="Generic Database Configuration"/>
<mongo:config name="mymongoconfig"   database="mydb1" doc:name="Mongo DB"/>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="replicateFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <db:select config-ref="MicrosoftSQLServerDB" doc:name="Database">
        <db:parameterized-query><![CDATA[Select * from [Electoral-Mechanicals P Ltd$Customer]]]></db:parameterized-query>
    </db:select>
    <logger message="No. of Records fetched from Table:#[payload.size()]" level="INFO" doc:name="Logger"/>
    <mongo:insert-object  collection="customer" config-ref="mymongoconfig" doc:name="Mongo DB"/>
</flow>
</mule>

甚至应用程序状态在运行应用程序后部署,但MongoDB中没有集合


        • 申请+ - - * - - +域名+ - - * - - +状态+ - - *
  • 复制*默认*部署*


你需要明确地创建一个集合。 您可以使用以下详细信息/示例来创建新集合。

创建集合

 '<mongo:create-collection>' 

创建一个新集合。 如果集合已存在,则抛出MongoException。

XML示例

 <mongo:create-collection config-ref="Mongo_DB__Configuration" collection="aCollection" capped="true"/> 

或者,

如果您决定首先检查一个具有相同名称的集合,并且您不想搞砸任何东西。 您可以使用以下内容:

存在集合

 <mongo:exists-collection> 

如果集合存在,则给出其名称XML Sample的答案

 <mongo:exists-collection config-ref="Mongo_DB__Configuration" collection="aColllection"/> 

要使用mule将文档插入mongodb中的集合,您需要

<mongo:insert-document 
config-ref="Mongo_DB__Configuration" 
collection="Employees"> </mongo:insert-document>

但是你正在使用

<mongo:insert-object> which i guess is not a valid API entity,

根据您拥有的版本,您需要使用InsertObject或InsertDocument。 大多数操作名称已更改为符合Mongo驱动程序v3,因此如果您有InsertObject操作,它现在显示为InsertDocument。

无论如何,要调用insertDocument操作,请在Mule中执行以下步骤:

  1. 找到并将HTTP连接器,转换消息和MongoDB连接器拖放到Anypoint Studio Canvas上。

  2. 通过选择Connector Configuration配置MongoDB连接器,并选择操作“InsertDocument”来调用它

  3. 单击“转换消息”,然后输入要插入的键值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM