Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated docs for 0.7

  • Loading branch information...
commit aea351a4a0f81bc30289880f68d2da63ab590809 1 parent ccde56f
@poiati authored
View
7 CHANGELOG.txt
@@ -1,3 +1,10 @@
+* 0.7
+ - Replica Set Support
+ - Added a constructor to com.gmongo.GMongo that take a com.mongodb.Mongo instance
+ - Support for com.mongodb.DBCursor#sort and other cursor methods
+ - groovy.lang.GString is now correctly handled by GMongo. Before 0.7 it can't be used as replacement for Strings in DBCollection methods
+ - Support for Groovy 1.7.7 and mongo-java-driver 2.4
+
* 0.6
- Collections truth. Empty collections are evaluated to false and non empty are evaluated to true in logical expression
- Better internal error handling
View
34 README.md
@@ -18,7 +18,7 @@ you need to get the Mongo reference just call com.gmongo.GMongo#getMongo.
Sample:
// To download GMongo on the fly and put it at classpath
- @Grab(group='com.gmongo', module='gmongo', version='0.5.1')
+ @Grab(group='com.gmongo', module='gmongo', version='0.7')
import com.gmongo.GMongo
// Instantiate a com.gmongo.GMongo object instead of com.mongodb.Mongo
// The same constructors and methods are available here
@@ -88,9 +88,39 @@ Sample:
db.languages.insert(name: 'Objective-C')
assert 1 == db.languages.count(name: 'Objective-C')
}
+
+## Sorting and Pagination
+ @Grab(group='com.gmongo', module='gmongo', version='0.7')
+ import com.gmongo.GMongo
+
+ def mongo = new GMongo()
+ def db = mongo.getDB("gmongo")
+
+ // Make sure that the collection is empty
+ db.example.drop()
+
+ // Insert 100 documents with any random value
+ 100.times {
+ db.example << [time: it, random: (Integer)(Math.random() * 100)]
+ }
+
+ def at = 0
+
+ // Find out how many documents are in the collection
+ def total = db.example.find().count()
+
+ // Sort the documents by the 'random' property ascending and Paginate over it 10 by 10
+ while (at < total) {
+ println "At page: ${at / 10}\n"
+ db.example.find().limit(10).skip(at).sort(random: 1).each {
+ println "\t-- ${it}"
+ }
+ println "\n--------------------------"
+ at += 10
+ }
## MapReduce
- @Grab(group='com.gmongo', module='gmongo', version='0.5.1')
+ @Grab(group='com.gmongo', module='gmongo', version='0.7')
import com.gmongo.GMongo
def mongo = new GMongo()
View
22 src/test/groovy/com/gmongo/UsageTest.groovy
@@ -73,6 +73,28 @@ class UsageTest extends GroovyTestCase {
assert 1 == db.languages.count(name: 'Objective-C')
}
}
+
+ void testSortingUsage() {
+ def mongo = new GMongo()
+ def db = mongo.getDB("gmongo")
+
+ db.example.drop()
+
+ 100.times {
+ db.example << [time: it, random: (Integer)(Math.random() * 100)]
+ }
+
+ def at = 0, total = db.example.find().count()
+
+ while (at < total) {
+ println "At page: ${at / 10}\n"
+ db.example.find().limit(10).skip(at).sort(random: 1).each {
+ println "\t-- ${it}"
+ }
+ println "\n--------------------------"
+ at += 10
+ }
+ }
void setUp() {
new GMongo().getDB("gmongo").dropDatabase()
Please sign in to comment.
Something went wrong with that request. Please try again.