【问题标题】:Why I am getting the WSO2 DSS Mapping issue?为什么我收到 WSO2 DSS 映射问题?
【发布时间】:2017-05-09 08:12:26
【问题描述】:

我正在尝试使用WSO2 DSS 映射我的 MongoDB。但是生成的服务是错误的,并且在数据映射方面出现了许多错误。

这是我尝试过的:

<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 DSS 从我的 MongoDB 获取 JSON 输出?

【问题讨论】:

    标签: mongodb wso2 wso2dss


    【解决方案1】:

    我们还在为 WSO2 + Mongo 之旅而苦苦挣扎。无论如何,我希望这会有所帮助。这是我们为 MongoDB 提供有效 JSON 服务的代码

    <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

    在我们这边,不幸的是,我们放弃了 WSO2 附带的 mongodb 适配器,并使用 RESTHeart 将 mongodb 公开为 API (http://restheart.org/) 这似乎工作得很好,因为 WSO2 然后就像使用它们一样消耗它们REST API。

    我们很想听听您的进展,因为我相信我们会在自己的 mongodb + WSO2 测试中遇到许多相同的挑战。

    【讨论】:

    • 我无法按照我的问题示例中分类的方式显示文档。比如说email带email标签和domain带domain标签之类的。你不觉得文档会给我一个完整的文档json,这就是我想要的,我想用category显示输出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多