Skip to content

Commit

Permalink
Exposed query as DBObject
Browse files Browse the repository at this point in the history
  • Loading branch information
timowest committed Apr 17, 2016
1 parent 5cdb0e3 commit 627df49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -411,6 +411,15 @@ public void setReadPreference(ReadPreference readPreference) {
this.readPreference = readPreference;
}

/**
* Get the where definition as a DBObject instance
*
* @return
*/
public DBObject asDBObject() {
return createQuery(queryMixin.getMetadata().getWhere());
}

@Override
public String toString() {
return createQuery(queryMixin.getMetadata().getWhere()).toString();
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.mongodb.morphia.Morphia;

import com.google.common.collect.Lists;
import com.mongodb.BasicDBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
import com.mongodb.ReadPreference;
Expand Down Expand Up @@ -579,7 +580,15 @@ public void readPreference() {
MorphiaQuery<User> query = query();
query.setReadPreference(ReadPreference.primary());
assertEquals(4, query.fetchCount());
}

@Test
public void asDBObject() {
MorphiaQuery<User> query = query();
query.where(user.firstName.eq("Bob"), user.lastName.eq("Wilson"));
assertEquals(
new BasicDBObject().append("firstName", "Bob").append("lastName", "Wilson"),
query.asDBObject());
}

//TODO
Expand Down

0 comments on commit 627df49

Please sign in to comment.