List of usage examples for com.mongodb MongoNamespace MongoNamespace
@BsonCreator public MongoNamespace(@BsonProperty("db") final String databaseName, @BsonProperty("coll") final String collectionName)
From source file:com.bluedragon.mongo.MongoCollectionRename.java
License:Open Source License
public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException { MongoDatabase db = getMongoDatabase(_session, argStruct); String collection = getNamedStringParam(argStruct, "collection", null); if (collection == null) throwException(_session, "please specify a collection"); String name = getNamedStringParam(argStruct, "name", null); if (name == null) throwException(_session, "please specify a name"); try {/* w w w .j a v a2s . c o m*/ db.getCollection(collection).renameCollection(new MongoNamespace(db.getName(), name), new RenameCollectionOptions().dropTarget(getNamedBooleanParam(argStruct, "droptarget", false))); return cfBooleanData.TRUE; } catch (MongoException me) { throwException(_session, me.getMessage()); return null; } }
From source file:io.lumeer.storage.mongodb.MongoDbStorage.java
License:Open Source License
@Override public void renameCollection(final String oldCollectionName, final String newCollectionName) { if (hasCollection(oldCollectionName)) { database.getCollection(oldCollectionName) .renameCollection(new MongoNamespace(database.getName(), newCollectionName)); }/*from w w w . j av a 2 s . co m*/ }
From source file:mongofx.js.api.Collection.java
License:Open Source License
public void renameCollection(String target, boolean dropTarget) { getCollection().renameCollection(new MongoNamespace(mongoDatabase.getName(), target), new RenameCollectionOptions().dropTarget(dropTarget)); }
From source file:mongofx.js.api.FindResultIterable.java
License:Open Source License
@JsIgnore @Override// w w w.j a va2 s . co m public MongoCursor<Document> iterator(int skip, int limit) { MongoCollection<Document> collection = getCollection(); findOptions.skip(skip); findOptions.limit(limit); if (projection != null) { findOptions.projection(projection); } if (sort != null) { findOptions.sort(dbObjectFromMap(sort)); } return new FindIterable(new MongoNamespace(mongoDatabase.getName(), collectionName), collection.getCodecRegistry(), // collection.getReadPreference(), getExecutor(), findQuery, findOptions).iterator(); }
From source file:mongofx.js.api.FindResultIterable.java
License:Open Source License
public ObjectListPresentation explain() { MongoCollection<Document> collection = getCollection(); FindIterable findIterable = new FindIterable(new MongoNamespace(mongoDatabase.getName(), collectionName), collection.getCodecRegistry(), // collection.getReadPreference(), getExecutor(), findQuery, findOptions); BsonDocument res = findIterable.explainIterator(ExplainVerbosity.QUERY_PLANNER); return JsApiUtils.singletonIter(JsApiUtils.convertBsonToDocument(res)); }
From source file:mongofx.ui.dbtree.DBTreeController.java
License:Open Source License
private void onReanameCollection(ActionEvent actionEvent) { TreeItem<DbTreeValue> selectedItem = treeView.getSelectionModel().getSelectedItem(); if (selectedItem == null) { return;/*from w w w .ja v a 2 s. co m*/ } DbTreeValue value = selectedItem.getValue(); TextInputDialog dialog = new TextInputDialog(value.getDisplayValue()); dialog.setContentText("New collection name:"); dialog.setHeaderText("Rename collection"); dialog.showAndWait().ifPresent(targetCollection -> { MongoCollection<Document> collection = value.getMongoDatabase().getMongoDb() .getCollection(value.getDisplayValue()); collection.renameCollection(new MongoNamespace(value.getMongoDatabase().getName(), targetCollection)); ((DynamicTreeItem) selectedItem.getParent()).reload(); }); }
From source file:org.springframework.data.mongodb.core.messaging.ChangeStreamTask.java
License:Apache License
@Override protected Message<ChangeStreamDocument<Document>, Object> createMessage(ChangeStreamDocument<Document> source, Class<Object> targetType, RequestOptions options) { // namespace might be null for eg. OperationType.INVALIDATE MongoNamespace namespace = Optional.ofNullable(source.getNamespace()) .orElse(new MongoNamespace("unknown", options.getCollectionName())); return new ChangeStreamEventMessage<>(new ChangeStreamEvent<>(source, targetType, mongoConverter), MessageProperties.builder().databaseName(namespace.getDatabaseName()) .collectionName(namespace.getCollectionName()).build()); }