From: Jean Privat Date: Mon, 30 Nov 2015 15:12:00 +0000 (-0500) Subject: Merge: mongodb: allow client to set `skip` and `limit` when calling `find` X-Git-Tag: v0.8~63 X-Git-Url: http://nitlanguage.org Merge: mongodb: allow client to set `skip` and `limit` when calling `find` Signed-off-by: Alexandre Terrasa Pull-Request: #1868 Reviewed-by: Romain Chanoir Reviewed-by: Jean Privat --- b3cc7d24e310cbd0ab271ee46640e561a7bada86 diff --cc lib/mongodb/mongodb.nit index fd753bd,64e68a0..78cd75d --- a/lib/mongodb/mongodb.nit +++ b/lib/mongodb/mongodb.nit @@@ -533,9 -612,12 +537,11 @@@ class MongoCollectio # var doc = col.find(query) # assert doc["foo"] == 10 # ~~~ - fun find(query: JsonObject): nullable JsonObject do + fun find(query: JsonObject, skip, limit: nullable Int): nullable JsonObject do - assert is_alive var q = new NativeBSON.from_json_string(query.to_json.to_cstring) - var c = native.find(q) + var s = skip or else 0 + var l = limit or else 0 + var c = native.find(q, s, l) q.destroy if c == null then return null var cursor = new MongoCursor(c) @@@ -556,15 -642,15 +566,17 @@@ # query["foo"] = 10 # assert col.find_all(query).length > 0 # ~~~ - fun find_all(query: JsonObject): Array[JsonObject] do + fun find_all(query: JsonObject, skip, limit: nullable Int): Array[JsonObject] do - assert is_alive + var s = skip or else 0 + var l = limit or else 0 var res = new Array[JsonObject] - var c = native.find(query.to_bson.native) + var c = native.find(query.to_bson.native, s, l) if c == null then return res var cursor = new MongoCursor(c) - for item in cursor do res.add item + while cursor.is_ok do + res.add cursor.item + cursor.next + end return res end