org.mongodb.MongoView Maven / Gradle / Ivy
package org.mongodb;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.WriteConcern;
public class MongoView {
private DBCursor surrogate;
private WriteConcern writeConcern;
public MongoView(final DBCursor cursor) {
this.surrogate = cursor;
}
public MongoView(final DBCursor cursor, final WriteConcern writeConcern) {
this.surrogate = cursor;
}
public MongoCursor get() {
return new MongoQueryCursor(surrogate);
}
public T getOne() {
return get().next();
}
public MongoView sort(final Document sort) {
surrogate = surrogate.sort(sort.getSurrogate());
return this;
}
public MongoView withWriteConcern(final WriteConcern writeConcern) {
this.writeConcern = writeConcern;
return this;
}
public void update(final Document updateQuery) {
DBObject query = surrogate.getQuery();
surrogate.getCollection().update(query, updateQuery.getSurrogate(), false, true, writeConcern);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy