2017-05-08 89 views
0

我正在尝试将我的MongoDB映射到WSO2 DSS。但是生成的服务存在错误,并且在数据映射方面出现很多错误。为什么我得到WSO2 DSS映射问题?

这里是我的尝试:

<data name="MongoDB" transports="http https local"> 
    <config enableOData="false" id="mongodb"> 
     <property name="mongoDB_servers">127.0.0.1:27017</property> 
     <property name="mongoDB_database">domain_with_email</property> 
     <property name="mongoDB_write_concern">NONE</property> 
     <property name="mongoDB_read_preference">PRIMARY</property> 
    </config> 
    <query id="search" useConfig="mongodb"> 
     <expression>domainemail.find({"domain":#})</expression> 
     <result escapeNonPrintableChar="true" outputType="json" useColumnNumbers="true">{&#xd;"entries":&#xd;{&#xd;"id":"$_id",&#xd;"domain":"$domain",&#xd;"emails":[&#xd; {&#xd; "email":"$email"&#xd; }&#xd;]&#xd;}&#xd;}</result> 
     <param defaultValue="yahoo.com" name="domain" sqlType="STRING"/> 
    </query> 
    <operation name="search"> 
     <call-query href="search"> 
     <with-param name="domain" query-param="domain"/> 
     </call-query> 
    </operation> 
</data> 

这里是错误:

https://gist.github.com/JafferWilson/b4aa22c39205d61a25f2bee5b45a7607

请让我知道我需要做的,使用WSO2我的MongoDB获得JSON输出DSS?

回答

1

我们仍然在为我们的WSO2 + Mongo旅程而苦苦挣扎。无论如何,我希望这可以帮助。下面是我们的工作JSON服务代码的MongoDB

<data name="MongoTestDS2" transports="http https local"> 
    <config enableOData="false" id="MongoDS"> 
     <property name="mongoDB_servers">xx.xx.xx.xx</property> 
     <property name="mongoDB_database">mydb</property> 
    </config> 
    <query id="GetTestVals" useConfig="MongoDS"> 
     <expression>things.find()</expression> 
     <result element="Documents" rowName="Document" useColumnNumbers="true"> 
     <element column="document" export="id" name="Data" xsdType="string"/> 
     </result> 
    </query> 
    <query id="InsertTestVals" returnUpdatedRowCount="true" useConfig="MongoDS"> 
     <expression>things.insert("{id:#, name:#}")</expression> 
     <result element="UpdatedRowCount" rowName="" useColumnNumbers="true"> 
     <element column="1" name="Value" xsdType="integer"/> 
     </result> 
     <param name="id" sqlType="STRING"/> 
     <param name="name" sqlType="STRING"/> 
    </query> 
    <query id="GetValsJson" useConfig="MongoDS"> 
     <expression>things.find()</expression> 
     <result outputType="json">{&#xd; "Documents": {&#xd; "Document": [&#xd; {&#xd; "Data": "$document"&#xd; }&#xd; ]&#xd; }&#xd;}</result> 
    </query> 
    <operation name="GetThings"> 
     <description>Test Mongo DB                 &#xd;         </description> 
     <call-query href="GetTestVals"/> 
    </operation> 
    <operation name="PutThings"> 
     <call-query href="InsertTestVals"> 
     <with-param name="id" query-param="id"/> 
     <with-param name="name" query-param="name"/> 
     </call-query> 
    </operation> 
    <operation name="GetThingsJson"> 
     <call-query href="GetValsJson"/> 
    </operation> 
</data> 

在你的情况,我认为,这是该行需要改变:

<query id="GetValsJson" useConfig="MongoDS"> 
     <expression>things.find()</expression> 
     <result outputType="json">{&#xd; "Documents": {&#xd; "Document": [&#xd; {&#xd; "Data": "$document"&#xd; }&#xd; ]&#xd; }&#xd;}</result> 
</query> 

这将返回所有字段为字符串。

如果这则涉及到你刚才的问题,那么我认为这个教程将与测绘领域从一个服务到另一个下一步骤的帮助: https://docs.wso2.com/display/EI611/Transforming+Message+Content

在我们身边,我们遗憾的是放弃了对mongodb适配器,附带WSO2并使用RESTHeart将mongodb作为API公开(http://restheart.org/)这看起来很好,因为WSO2只是像使用其他REST API一样使用它们。

我们很乐意听取您的意见,因为我确信我们会在我们自己的mongodb + WSO2测试中遇到许多相同的挑战。

+0

有没有办法,我可以按照我的问题示例中分类的方式显示文档。说像电子邮件与电子邮件标签和域名与域标签等,你不觉得该文件会给我一个完整的文件JSON,这是我想我想显示输出的类别。 –