This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Unroll | |
def 'should generate index name #indexName for #index'() { | |
expect: | |
index.getName() == indexName; | |
where: | |
index | indexName | |
new Index('x') | 'x_1' | |
new Index('x', OrderBy.ASC) | 'x_1' | |
new Index('x', OrderBy.DESC) | 'x_-1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoClient mongoClient = new MongoClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB database = mongoClient.getDB("TheDatabaseName"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBCollection collection = database.getCollection("TheCollectionName"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Integer> books = Arrays.asList(27464, 747854); | |
DBObject person = new BasicDBObject("_id", "jo") | |
.append("name", "Jo Bloggs") | |
.append("address", new BasicDBObject("street", "123 Fake St") | |
.append("city", "Faketon") | |
.append("state", "MA") | |
.append("zip", 12345)) | |
.append("books", books); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MongoClient mongoClient = new MongoClient(); | |
DB database = mongoClient.getDB("Examples"); | |
DBCollection collection = database.getCollection("people"); | |
collection.insert(person); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final DBObject toDBObject(Person person) { | |
return new BasicDBObject("_id", person.getId()) | |
.append("name", person.getName()) | |
.append("address", new BasicDBObject("street", person.getAddress().getStreet()) | |
.append("city", person.getAddress().getTown()) | |
.append("phone", person.getAddress().getPhone())) | |
.append("books", person.getBookIds()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection.insert(PersonAdaptor.toDBObject(myPerson)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBObject query = new BasicDBObject("_id", "jo"); | |
DBCursor cursor = collection.find(query); |