2017-04-21 8 views
1
This is the inbound channel adapter which fetches the matching criteria records 
from the DB: 

<!-- language: lang-xml --> 

    <int-mongodb:inbound-channel-adapter 
     id="simpleInboundAdapter" channel="pollingInputChannel" 
     query="{$or:[{'status':'New'},{$and:[{'status':'Failure'},{'noOfRetries':{$lt:3}}]}]}" 
     collection-name="custommessages" entity-class="com.att.ssp.deviceeventprocessor.model.CustomMessage" 
     mongodb-factory="mongoDbFactory"> 
     <int:poller fixed-rate="30000" max-messages-per-poll="1"> 
      <!-- <int:transactional synchronization-factory="txSyncFactory" /> --> 
     </int:poller> 
    </int-mongodb:inbound-channel-adapter> 


My use case is that I need to restrict the number of records fetched. 
Say I have 100 records matching the criteria but I want only 10 records to be fetched. Can any one help me how to achieve that functionality here. 

からフェッチされたレコードの数を制限したいです手.. いずれかが本当に助けthis.Anyのために一日中苦しんでいたしてくださいを助けることができる私は、私もこのexmapleと試みたが、まだレコードのどれもここでフェッチされていない私のMongoDB

<int-mongodb:inbound-channel-adapter 
     id="simpleInboundAdapter" channel="pollingInputChannel" 
     query-expression="new BasicQuery('{''status'' : ''New''}').limit(2)" 
     collection-name="custommessages" entity-class="com.att.ssp.deviceeventprocessor.model.CustomMessage" 
     mongodb-factory="mongoDbFactory"> 
     <int:poller fixed-rate="30000" max-messages-per-poll="1"> 
      <!-- <int:transactional synchronization-factory="txSyncFactory" /> --> 
      </int:poller> 
    </int-mongodb:inbound-channel-adapter> 

これはレコード数をフィルタリングするための理想的な方法となりますインバウンドアダプタ... または何をモンゴreocordsフィルタを形成するために間違ったapprochでください。

+0

使用$限度演算子私はuのlimit..can $を使用することができ、返信用 – felix

+0

こんにちはフェリックスのおかげで提案してください春のときの積分に新しいですと、 .. –

+0

@felixあなたは答えとして投稿する必要があります –

答えて

0

$limitaggregationの一部であり、<int-mongodb:inbound-channel-adapterので、私たちはその$limitを使用することはできませんfind()に基づいています。

limit()cursorです。

春の統合4.3.6ため、このような機能が提供されています:

query-expression="new BasicQuery('{$or:[{''status'':''New''},{$and:[{''status'':''Failure''},{''noOfRetries'':{$lt:3}}]}]}').limit(100)" 
+0

こんにちはArtem私はこのapprochに疲れているが、それでも動作していません。 –

+0

OK!あなたの質問を、特定の情報と実行結果で更新してください。 –

+0

申し訳ありませんArtemが投稿した構文は、春のintergration jar 4.3.8.Soのために正常に動作しています。私はspring integration jarの古いバージョンを使用していました。 –

関連する問題