|
46 | 46 | import org.bson.types.ObjectId;
|
47 | 47 | import org.reactivestreams.Publisher;
|
48 | 48 | import org.reactivestreams.Subscriber;
|
49 |
| - |
50 | 49 | import org.springframework.beans.BeansException;
|
51 | 50 | import org.springframework.context.ApplicationContext;
|
52 | 51 | import org.springframework.context.ApplicationContextAware;
|
|
81 | 80 | import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
82 | 81 | import org.springframework.data.mongodb.core.aggregation.AggregationOperationContext;
|
83 | 82 | import org.springframework.data.mongodb.core.aggregation.AggregationOptions;
|
| 83 | +import org.springframework.data.mongodb.core.aggregation.AggregationPipeline; |
84 | 84 | import org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext;
|
85 | 85 | import org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext;
|
86 | 86 | import org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext;
|
|
127 | 127 | import com.mongodb.MongoException;
|
128 | 128 | import com.mongodb.ReadPreference;
|
129 | 129 | import com.mongodb.WriteConcern;
|
130 |
| -import com.mongodb.client.model.CountOptions; |
131 |
| -import com.mongodb.client.model.CreateCollectionOptions; |
132 |
| -import com.mongodb.client.model.DeleteOptions; |
133 |
| -import com.mongodb.client.model.EstimatedDocumentCountOptions; |
134 |
| -import com.mongodb.client.model.FindOneAndDeleteOptions; |
135 |
| -import com.mongodb.client.model.FindOneAndReplaceOptions; |
136 |
| -import com.mongodb.client.model.FindOneAndUpdateOptions; |
137 |
| -import com.mongodb.client.model.ReplaceOptions; |
138 |
| -import com.mongodb.client.model.ReturnDocument; |
139 |
| -import com.mongodb.client.model.UpdateOptions; |
| 130 | +import com.mongodb.client.model.*; |
140 | 131 | import com.mongodb.client.model.changestream.FullDocument;
|
141 | 132 | import com.mongodb.client.result.DeleteResult;
|
142 | 133 | import com.mongodb.client.result.InsertOneResult;
|
@@ -671,6 +662,42 @@ public Mono<MongoCollection<Document>> createCollection(String collectionName,
|
671 | 662 | return doCreateCollection(collectionName, convertToCreateCollectionOptions(collectionOptions));
|
672 | 663 | }
|
673 | 664 |
|
| 665 | + @Override |
| 666 | + public Mono<MongoCollection<Document>> createView(String name, Class<?> source, AggregationPipeline pipeline, @Nullable ViewOptions options) { |
| 667 | + |
| 668 | + return createView(name, getCollectionName(source), |
| 669 | + queryOperations.createAggregation(Aggregation.newAggregation(source, pipeline.getOperations()), source), |
| 670 | + options); |
| 671 | + } |
| 672 | + |
| 673 | + @Override |
| 674 | + public Mono<MongoCollection<Document>> createView(String name, String source, AggregationPipeline pipeline, |
| 675 | + @Nullable ViewOptions options) { |
| 676 | + |
| 677 | + return createView(name, source, |
| 678 | + queryOperations.createAggregation(Aggregation.newAggregation(pipeline.getOperations()), (Class<?>) null), |
| 679 | + options); |
| 680 | + } |
| 681 | + |
| 682 | + private Mono<MongoCollection<Document>> createView(String name, String source, AggregationDefinition aggregation, |
| 683 | + @Nullable ViewOptions options) { |
| 684 | + return doCreateView(name, source, aggregation.getAggregationPipeline(), options); |
| 685 | + } |
| 686 | + |
| 687 | + protected Mono<MongoCollection<Document>> doCreateView(String name, String source, List<Document> pipeline, |
| 688 | + @Nullable ViewOptions options) { |
| 689 | + |
| 690 | + CreateViewOptions viewOptions = new CreateViewOptions(); |
| 691 | + if (options != null) { |
| 692 | + options.getCollation().map(Collation::toMongoCollation).ifPresent(viewOptions::collation); |
| 693 | + } |
| 694 | + |
| 695 | + return execute(db -> { |
| 696 | + return Flux.from(db.createView(name, source, pipeline, viewOptions)) |
| 697 | + .then(Mono.fromSupplier(() -> db.getCollection(name))); |
| 698 | + }).next(); |
| 699 | + } |
| 700 | + |
674 | 701 | @Override
|
675 | 702 | public Mono<MongoCollection<Document>> getCollection(String collectionName) {
|
676 | 703 |
|
|
0 commit comments