UNPKG

12.3 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var Repository_1 = require("./Repository");
5/**
6 * Repository used to manage mongodb documents of a single entity type.
7 */
8var MongoRepository = /** @class */ (function (_super) {
9 tslib_1.__extends(MongoRepository, _super);
10 function MongoRepository() {
11 return _super !== null && _super.apply(this, arguments) || this;
12 }
13 // -------------------------------------------------------------------------
14 // Overridden Methods
15 // -------------------------------------------------------------------------
16 /**
17 * Raw SQL query execution is not supported by MongoDB.
18 * Calling this method will return an error.
19 */
20 MongoRepository.prototype.query = function (query, parameters) {
21 throw new Error("Queries aren't supported by MongoDB.");
22 };
23 /**
24 * Using Query Builder with MongoDB is not supported yet.
25 * Calling this method will return an error.
26 */
27 MongoRepository.prototype.createQueryBuilder = function (alias, queryRunner) {
28 throw new Error("Query Builder is not supported by MongoDB.");
29 };
30 /**
31 * Finds entities that match given find options or conditions.
32 */
33 MongoRepository.prototype.find = function (optionsOrConditions) {
34 return this.manager.find(this.metadata.target, optionsOrConditions);
35 };
36 /**
37 * Finds entities that match given find options or conditions.
38 * Also counts all entities that match given conditions,
39 * but ignores pagination settings (from and take options).
40 */
41 MongoRepository.prototype.findAndCount = function (optionsOrConditions) {
42 return this.manager.findAndCount(this.metadata.target, optionsOrConditions);
43 };
44 /**
45 * Finds entities by ids.
46 * Optionally find options can be applied.
47 */
48 MongoRepository.prototype.findByIds = function (ids, optionsOrConditions) {
49 return this.manager.findByIds(this.metadata.target, ids, optionsOrConditions);
50 };
51 /**
52 * Finds first entity that matches given conditions and/or find options.
53 */
54 MongoRepository.prototype.findOne = function (optionsOrConditions, maybeOptions) {
55 return this.manager.findOne(this.metadata.target, optionsOrConditions, maybeOptions);
56 };
57 /**
58 * Creates a cursor for a query that can be used to iterate over results from MongoDB.
59 */
60 MongoRepository.prototype.createCursor = function (query) {
61 return this.manager.createCursor(this.metadata.target, query);
62 };
63 /**
64 * Creates a cursor for a query that can be used to iterate over results from MongoDB.
65 * This returns modified version of cursor that transforms each result into Entity model.
66 */
67 MongoRepository.prototype.createEntityCursor = function (query) {
68 return this.manager.createEntityCursor(this.metadata.target, query);
69 };
70 /**
71 * Execute an aggregation framework pipeline against the collection.
72 */
73 MongoRepository.prototype.aggregate = function (pipeline, options) {
74 return this.manager.aggregate(this.metadata.target, pipeline, options);
75 };
76 /**
77 * Execute an aggregation framework pipeline against the collection.
78 * This returns modified version of cursor that transforms each result into Entity model.
79 */
80 MongoRepository.prototype.aggregateEntity = function (pipeline, options) {
81 return this.manager.aggregateEntity(this.metadata.target, pipeline, options);
82 };
83 /**
84 * Perform a bulkWrite operation without a fluent API.
85 */
86 MongoRepository.prototype.bulkWrite = function (operations, options) {
87 return this.manager.bulkWrite(this.metadata.target, operations, options);
88 };
89 /**
90 * Count number of matching documents in the db to a query.
91 */
92 MongoRepository.prototype.count = function (query, options) {
93 return this.manager.count(this.metadata.target, query || {}, options);
94 };
95 /**
96 * Creates an index on the db and collection.
97 */
98 MongoRepository.prototype.createCollectionIndex = function (fieldOrSpec, options) {
99 return this.manager.createCollectionIndex(this.metadata.target, fieldOrSpec, options);
100 };
101 /**
102 * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher.
103 * Earlier version of MongoDB will throw a command not supported error.
104 * Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.
105 */
106 MongoRepository.prototype.createCollectionIndexes = function (indexSpecs) {
107 return this.manager.createCollectionIndexes(this.metadata.target, indexSpecs);
108 };
109 /**
110 * Delete multiple documents on MongoDB.
111 */
112 MongoRepository.prototype.deleteMany = function (query, options) {
113 return this.manager.deleteMany(this.metadata.tableName, query, options);
114 };
115 /**
116 * Delete a document on MongoDB.
117 */
118 MongoRepository.prototype.deleteOne = function (query, options) {
119 return this.manager.deleteOne(this.metadata.tableName, query, options);
120 };
121 /**
122 * The distinct command returns returns a list of distinct values for the given key across a collection.
123 */
124 MongoRepository.prototype.distinct = function (key, query, options) {
125 return this.manager.distinct(this.metadata.tableName, key, query, options);
126 };
127 /**
128 * Drops an index from this collection.
129 */
130 MongoRepository.prototype.dropCollectionIndex = function (indexName, options) {
131 return this.manager.dropCollectionIndex(this.metadata.tableName, indexName, options);
132 };
133 /**
134 * Drops all indexes from the collection.
135 */
136 MongoRepository.prototype.dropCollectionIndexes = function () {
137 return this.manager.dropCollectionIndexes(this.metadata.tableName);
138 };
139 /**
140 * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
141 */
142 MongoRepository.prototype.findOneAndDelete = function (query, options) {
143 return this.manager.findOneAndDelete(this.metadata.tableName, query, options);
144 };
145 /**
146 * Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.
147 */
148 MongoRepository.prototype.findOneAndReplace = function (query, replacement, options) {
149 return this.manager.findOneAndReplace(this.metadata.tableName, query, replacement, options);
150 };
151 /**
152 * Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.
153 */
154 MongoRepository.prototype.findOneAndUpdate = function (query, update, options) {
155 return this.manager.findOneAndUpdate(this.metadata.tableName, query, update, options);
156 };
157 /**
158 * Execute a geo search using a geo haystack index on a collection.
159 */
160 MongoRepository.prototype.geoHaystackSearch = function (x, y, options) {
161 return this.manager.geoHaystackSearch(this.metadata.tableName, x, y, options);
162 };
163 /**
164 * Execute the geoNear command to search for items in the collection.
165 */
166 MongoRepository.prototype.geoNear = function (x, y, options) {
167 return this.manager.geoNear(this.metadata.tableName, x, y, options);
168 };
169 /**
170 * Run a group command across a collection.
171 */
172 MongoRepository.prototype.group = function (keys, condition, initial, reduce, finalize, command, options) {
173 return this.manager.group(this.metadata.tableName, keys, condition, initial, reduce, finalize, command, options);
174 };
175 /**
176 * Retrieve all the indexes on the collection.
177 */
178 MongoRepository.prototype.collectionIndexes = function () {
179 return this.manager.collectionIndexes(this.metadata.tableName);
180 };
181 /**
182 * Retrieve all the indexes on the collection.
183 */
184 MongoRepository.prototype.collectionIndexExists = function (indexes) {
185 return this.manager.collectionIndexExists(this.metadata.tableName, indexes);
186 };
187 /**
188 * Retrieves this collections index info.
189 */
190 MongoRepository.prototype.collectionIndexInformation = function (options) {
191 return this.manager.collectionIndexInformation(this.metadata.tableName, options);
192 };
193 /**
194 * Initiate an In order bulk write operation, operations will be serially executed in the order they are added, creating a new operation for each switch in types.
195 */
196 MongoRepository.prototype.initializeOrderedBulkOp = function (options) {
197 return this.manager.initializeOrderedBulkOp(this.metadata.tableName, options);
198 };
199 /**
200 * Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
201 */
202 MongoRepository.prototype.initializeUnorderedBulkOp = function (options) {
203 return this.manager.initializeUnorderedBulkOp(this.metadata.tableName, options);
204 };
205 /**
206 * Inserts an array of documents into MongoDB.
207 */
208 MongoRepository.prototype.insertMany = function (docs, options) {
209 return this.manager.insertMany(this.metadata.tableName, docs, options);
210 };
211 /**
212 * Inserts a single document into MongoDB.
213 */
214 MongoRepository.prototype.insertOne = function (doc, options) {
215 return this.manager.insertOne(this.metadata.tableName, doc, options);
216 };
217 /**
218 * Returns if the collection is a capped collection.
219 */
220 MongoRepository.prototype.isCapped = function () {
221 return this.manager.isCapped(this.metadata.tableName);
222 };
223 /**
224 * Get the list of all indexes information for the collection.
225 */
226 MongoRepository.prototype.listCollectionIndexes = function (options) {
227 return this.manager.listCollectionIndexes(this.metadata.tableName, options);
228 };
229 /**
230 * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
231 */
232 MongoRepository.prototype.mapReduce = function (map, reduce, options) {
233 return this.manager.mapReduce(this.metadata.tableName, map, reduce, options);
234 };
235 /**
236 * Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
237 * There are no ordering guarantees for returned results.
238 */
239 MongoRepository.prototype.parallelCollectionScan = function (options) {
240 return this.manager.parallelCollectionScan(this.metadata.tableName, options);
241 };
242 /**
243 * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
244 */
245 MongoRepository.prototype.reIndex = function () {
246 return this.manager.reIndex(this.metadata.tableName);
247 };
248 /**
249 * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
250 */
251 MongoRepository.prototype.rename = function (newName, options) {
252 return this.manager.rename(this.metadata.tableName, newName, options);
253 };
254 /**
255 * Replace a document on MongoDB.
256 */
257 MongoRepository.prototype.replaceOne = function (query, doc, options) {
258 return this.manager.replaceOne(this.metadata.tableName, query, doc, options);
259 };
260 /**
261 * Get all the collection statistics.
262 */
263 MongoRepository.prototype.stats = function (options) {
264 return this.manager.stats(this.metadata.tableName, options);
265 };
266 /**
267 * Update multiple documents on MongoDB.
268 */
269 MongoRepository.prototype.updateMany = function (query, update, options) {
270 return this.manager.updateMany(this.metadata.tableName, query, update, options);
271 };
272 /**
273 * Update a single document on MongoDB.
274 */
275 MongoRepository.prototype.updateOne = function (query, update, options) {
276 return this.manager.updateOne(this.metadata.tableName, query, update, options);
277 };
278 return MongoRepository;
279}(Repository_1.Repository));
280exports.MongoRepository = MongoRepository;
281
282//# sourceMappingURL=MongoRepository.js.map