我想限制从MongoDB获取的记录数

时间:2017-04-21 09:34:09

标签: mongodb mongodb-query spring-integration

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.change_password_activity);
            list(getIntent().getExtras().getString("JSON_Object"));
            CurrentPwdCheck();
            NewpwdCheck();

            btnSubmit= (Button) findViewById(R.id.btnSubmit);
            btnSubmit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    try {
                       NewPasword pwd = new NewPasword();
                       pwd.start(); 
                    } catch (IOException e) {
                        e.printStackTrace();

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

    class NewPasword extends Thread{
            @Override
            public void run() {
            String myPwd=new_pwd.getText().toString();

            String Surl="http://inmeets.com/ChangePwd.php?uid="+uid+"&NewPwd="+myPwd;

            URL url = null;
            HttpURLConnection conn = null;


                url = new URL(Surl);
            conn = (HttpURLConnection)url.openConnection();
            conn.setRequestMethod("GET");
            conn.setConnectTimeout(1000);
           if( conn.getResponseCode()==203) {
     getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                                   Toast.makeText(getBaseContext(), "your password 
                     changed", Toast.LENGTH_SHORT).show();
                    }
                });

           }
            }
        }

我甚至试过这个例子,但仍然没有记录在这里取得任何一个真正帮助,请为这一整天挣扎。请帮助我。

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.

这是错误的approch过滤recoords形式mongo入站适配器.. 或者什么是过滤记录计数的理想方式。

1 个答案:

答案 0 :(得分:0)

$limitaggregation的一部分,由于<int-mongodb:inbound-channel-adapter基于find()我们无法使用$limit

我们这里只有来自cursorlimit()

自Spring Integration 4.3.6以来可以使用这样的功能:

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