Skip to content

Instantly share code, notes, and snippets.

View trishagee's full-sized avatar

Trisha Gee trishagee

View GitHub Profile
@trishagee
trishagee / build.gradle
Created August 8, 2013 11:14
Build file for gradle with the dependency for the 3.0 Java driver for MongoDB with the old, compatible API.
apply plugin: 'java'
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
compile 'org.mongodb:mongo-java-driver:3.0.0-SNAPSHOT'
@trishagee
trishagee / pom.xml
Created August 8, 2013 11:37
POM file for the new 3.0 Java driver for MongoDB with the new API.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mongodb.test</groupId>
<artifactId>3.0-test</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
@trishagee
trishagee / build.gradle
Last active December 20, 2015 19:29
Build file for gradle with the dependency for the new 3.0 Java driver for MongoDB and the new API.
apply plugin: 'java'
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
compile 'org.mongodb:mongodb-driver:3.0.0-SNAPSHOT'
10 PRINT "HELLO"
20 GOTO 10
Document query = new Document(theKey, type);
MongoView<MyThing> results = myCollection.find(query);
return results.into(new ArrayList<MyThing>());
@Test()
public void testSingleServer() {
MongoClientURI u = new MongoClientURI("mongodb://db.example.com");
assertEquals(1, u.getHosts().size());
assertEquals("db.example.com", u.getHosts().get(0));
assertNull(u.getDatabase());
assertNull(u.getCollection());
assertNull( u.getUsername());
assertEquals(null, u.getPassword());
}
@Unroll
def 'should parse #uri into correct components'() {
expect:
uri.getHosts().size() == num;
uri.getHosts() == hosts;
uri.getDatabase() == database;
uri.getCollection() == collection;
uri.getUsername() == username;
uri.getPassword() == password;
@Test
public void testGetLastErrorCommand() {
assertEquals(new BasicDBObject("getlasterror", 1), WriteConcern.UNACKNOWLEDGED.getCommand());
assertEquals(new BasicDBObject("getlasterror", 1), WriteConcern.ACKNOWLEDGED.getCommand());
assertEquals(new BasicDBObject("getlasterror", 1).append("w", 2), WriteConcern.REPLICA_ACKNOWLEDGED.getCommand());
assertEquals(new BasicDBObject("getlasterror", 1).append("j", true), WriteConcern.JOURNALED.getCommand());
assertEquals(new BasicDBObject("getlasterror", 1).append("fsync", true), WriteConcern.FSYNCED.getCommand());
assertEquals(new BasicDBObject("getlasterror", 1).append("w", "majority"), new WriteConcern("majority").getCommand());
assertEquals(new BasicDBObject("getlasterror", 1).append("wtimeout", 100), new WriteConcern(1, 100).getCommand());
}
@Unroll
def '#wc should return getlasterror document #commandDocument'() {
expect:
wc.asDocument() == commandDocument;
where:
wc | commandDocument
WriteConcern.UNACKNOWLEDGED | ['getlasterror': 0]
WriteConcern.ACKNOWLEDGED | ['getlasterror': 1]
WriteConcern.REPLICA_ACKNOWLEDGED | ['getlasterror': 1, 'w': 2]
@Test
public void shouldGenerateIndexNameForSimpleKey() {
final Index index = new Index("x");
assertEquals("x_1", index.getName());
}
@Test
public void shouldGenerateIndexNameForKeyOrderedAscending() {
final Index index = new Index("x", OrderBy.ASC);
assertEquals("x_1", index.getName());