All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mongodb.MongoCollection Maven / Gradle / Ivy

Go to download

An extension to the MongoDB Java Driver library that goes beyond what the GridFS feature supports. Compressed file storage, zip files, temporary files

There is a newer version: 0.10.0
Show newest version
package org.mongodb;

import com.mongodb.DBCollection;
import com.mongodb.DBObject;

public class MongoCollection {

    private DBCollection surrogate;

    public MongoCollection(final DBCollection db) {
        this.surrogate = db;
    }

    public void save(final Document document) {

        DBObject dbObject = document.getSurrogate();

        Object id = dbObject.get("_id");
        if (id == null) {
            surrogate.insert(dbObject);
        }
        else {
            surrogate.save(dbObject);
        }
    }

    public String getName() {
        return surrogate.getName();
    }

    public MongoDatabase getDatabase() {
        return new MongoDatabase(surrogate.getDB());
    }

    public MongoView find(final Document in) {
        return new MongoView(surrogate.find(in.getSurrogate()));
    }

    public CollectionAdministration tools() {
        return new CollectionAdministration(surrogate);
    }

    public WriteResult remove(final Document filesQuery) {
        return new WriteResult(surrogate.remove(filesQuery.getSurrogate()));
    }

    public void createIndex(final Document document) {
        surrogate.createIndex(document.getSurrogate());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy