List of usage examples for com.mongodb.client.model Indexes ascending
public static Bson ascending(final List<String> fieldNames)
From source file:com.centurylink.mdw.mongo.MongoDocumentDb.java
License:Apache License
public static void createMongoDocIdIndex(String collectionName) { IndexOptions indexOptions = new IndexOptions().unique(true).background(true); MongoCollection<org.bson.Document> collection = mongoClient.getDatabase("mdw") .getCollection(collectionName); String indexName = collection.createIndex(Indexes.ascending("document_id"), indexOptions); LoggerUtil.getStandardLogger()//from w w w. j av a 2s. c o m .mdwDebug("Created Index : " + indexName + " on collection : " + collectionName); collectionDocIdIndexed.putIfAbsent(collectionName, Boolean.valueOf(true)); }
From source file:com.github.achatain.catalog.dao.impl.CollectionDaoImpl.java
License:Open Source License
@Override public void createIndex(final String userId, final String collectionId, final String fieldName) { getDatabase(userId).getCollection(collectionId).createIndex( Indexes.ascending(ATTRIBUTES_PREFIX + fieldName), new IndexOptions().name(fieldName).background(true)); }
From source file:com.mycompany.citysearchnosql.Executioner.java
public static void main(final String[] args) { // 1. Connect to MongoDB instance running on localhost MongoClient mongoClient = new MongoClient(); // Access database named 'test' MongoDatabase database = mongoClient.getDatabase("test"); // Access collection named 'restaurants' MongoCollection<Document> collection = database.getCollection("restaurants"); // 2. Insert List<Document> documents = asList( new Document("name", "Sun Bakery Trattoria").append("stars", 4).append("categories", asList("Pizza", "Pasta", "Italian", "Coffee", "Sandwiches")), new Document("name", "Blue Bagels Grill").append("stars", 3).append("categories", asList("Bagels", "Cookies", "Sandwiches")), new Document("name", "Hot Bakery Cafe").append("stars", 4).append("categories", asList("Bakery", "Cafe", "Coffee", "Dessert")), new Document("name", "XYZ Coffee Bar").append("stars", 5).append("categories", asList("Coffee", "Cafe", "Bakery", "Chocolates")), new Document("name", "456 Cookies Shop").append("stars", 4).append("categories", asList("Bakery", "Cookies", "Cake", "Coffee"))); collection.insertMany(documents);/* ww w . ja va 2 s.com*/ // 3. Query List<Document> results = collection.find().into(new ArrayList<>()); // 4. Create Index collection.createIndex(Indexes.ascending("name")); // 5. Perform Aggregation collection.aggregate(asList(match(eq("categories", "Bakery")), group("$stars", sum("count", 1)))); mongoClient.close(); }
From source file:com.sitewhere.asset.persistence.mongodb.MongoAssetManagement.java
License:Open Source License
/** * Ensure that expected collection indexes exist. * //from ww w. ja v a2 s . c o m * @throws SiteWhereException */ protected void ensureIndexes() throws SiteWhereException { getMongoClient().getAssetTypesCollection().createIndex(Indexes.ascending(MongoAssetType.PROP_TOKEN), new IndexOptions().unique(true)); getMongoClient().getAssetsCollection().createIndex(Indexes.ascending(MongoAsset.PROP_TOKEN), new IndexOptions().unique(true)); }
From source file:io.lumeer.storage.mongodb.dao.organization.MongoCompanyContactDao.java
License:Open Source License
@Override public void createCompanyContactRepository() { if (database.getCollection(COMPANY_CONTACT_COLLECTION) == null) { database.createCollection(COMPANY_CONTACT_COLLECTION); MongoCollection<Document> companyContactCollection = database.getCollection(COMPANY_CONTACT_COLLECTION); companyContactCollection.createIndex(Indexes.ascending(CompanyContactCodec.ORGANIZATION_ID), new IndexOptions().unique(true)); }// ww w . j a v a 2 s . c o m }
From source file:io.lumeer.storage.mongodb.dao.organization.MongoPaymentDao.java
License:Open Source License
@Override public void createPaymentRepository(final Organization organization) { database.createCollection(databaseCollectionName(organization)); MongoCollection<Document> groupCollection = database.getCollection(databaseCollectionName(organization)); groupCollection.createIndex(Indexes.ascending(PaymentCodec.PAYMENT_ID), new IndexOptions().unique(true)); groupCollection.createIndex(Indexes.descending(PaymentCodec.DATE), new IndexOptions().unique(true)); groupCollection.createIndex(Indexes.descending(PaymentCodec.START), new IndexOptions().unique(true)); groupCollection.createIndex(Indexes.descending(PaymentCodec.VALID_UNTIL), new IndexOptions().unique(true)); }
From source file:io.lumeer.storage.mongodb.dao.project.MongoViewDao.java
License:Open Source License
@Override public void createViewsRepository(Project project) { database.createCollection(databaseCollectionName(project)); MongoCollection<Document> projectCollection = database.getCollection(databaseCollectionName(project)); projectCollection.createIndex(Indexes.ascending(ViewCodec.CODE), new IndexOptions().unique(true)); projectCollection.createIndex(Indexes.ascending(ViewCodec.NAME), new IndexOptions().unique(true)); projectCollection.createIndex(Indexes.text(ViewCodec.NAME)); }
From source file:io.lumeer.storage.mongodb.dao.project.MorphiaDocumentDao.java
License:Open Source License
@Override public void createDocumentsRepository(final Project project) { database.createCollection(databaseCollection(project)); datastore.ensureIndexes(databaseCollection(project), MorphiaDocument.class); database.getCollection(databaseCollection(project)) .createIndex(Indexes.ascending(MorphiaDocument.META_DATA + "." + Document.META_PARENT_ID)); }
From source file:io.lumeer.storage.mongodb.dao.system.MongoGroupDao.java
License:Open Source License
@Override public void createGroupsRepository(Organization organization) { database.createCollection(databaseCollectionName(organization)); MongoCollection<Document> groupCollection = database.getCollection(databaseCollectionName(organization)); groupCollection.createIndex(Indexes.ascending(GroupCodec.NAME), new IndexOptions().unique(true)); }
From source file:io.lumeer.storage.mongodb.dao.system.MongoUserDao.java
License:Open Source License
public void createUsersRepository() { database.createCollection(databaseCollectionName()); MongoCollection<Document> userCollection = database.getCollection(databaseCollectionName()); userCollection.createIndex(Indexes.ascending(UserCodec.EMAIL), new IndexOptions().unique(true)); }