我有一个包含超过31,000个文档的集合,我希望从我的Java HTTP(我使用服务)调用中检索每个调用的x个文档数:
public void sendGet()throws Exception{
//using find service to get all nodes
String url = "service url"; // "http:....."
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", userAgent);
//200 -OK
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
IterationForDocuments+=100; // set to 0;
}对于每个电话,我希望得到docs 1-100,对于下一个电话,我想得到101-200等等,直到结束。我的问题是:1-在java data-types中是否有一个很好的方法来实现data-types 100文档。2-我应该将索引跟踪服务(Mongo)或java类放在哪里?下面是我使用的mongo查询:
module.exports = function (app, options) {
var mongoFind = {
events: mongoFindEvents,
find: function (req, res) {
var name = "node"
var query = {};
query = req.query;
var Collection = getCollection(name);
Collection.find(query).toArray(function(err, docs) {
res.send(docs);
});
}
};谢谢!
发布于 2015-11-16 18:26:28
您并没有展示如何在这个片段中实际查询您的MongoDb,但是您需要做的是为您希望检索的文档组发送一个查询参数。然后,在实际查询MongoDb的代码中,需要使用limit和和skip运算符来提取正确的数据。因此,您的HTTP请求对象将类似于(以JSON格式):
{
User-Agent: <user-agent>
Skip: ### //ie 100, 200, 300, etc
Limit: ### //Sounds like you always want this to be 100
}然后,在您的查询中(同样,您没有显示实际查询Mongo的代码,所以我只是编写它,因为它将在Mongo shell中显示):
db.collection.find(<query>).skip(request.skip).limit(request.limit)https://stackoverflow.com/questions/33739003
复制相似问题