Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typeodm

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeodm - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

driver/options/AggergationOptions.js

342

driver/MongodbDriver.js

@@ -67,9 +67,24 @@ "use strict";

}, {
key: "insert",
value: function insert(collection, document) {
key: "createObjectId",
value: function createObjectId(id) {
return new _mongodb.ObjectID(id);
}
}, {
key: "isObjectId",
value: function isObjectId(id) {
return id instanceof _mongodb.ObjectID;
}
}, {
key: "getIdFieldName",
value: function getIdFieldName() {
return '_id';
}
}, {
key: "dropDatabase",
value: function dropDatabase() {
var _this3 = this;
return new Promise(function (ok, fail) {
_this3.db.collection(collection).insert([document], function (err, result) {
return err ? fail(err) : ok(result.ops[0]);
_this3.db.dropDatabase(function (err, result) {
return err ? fail(err) : ok();
});

@@ -79,9 +94,9 @@ });

}, {
key: "bulkInsert",
value: function bulkInsert(collection, documents) {
key: "dropCollection",
value: function dropCollection(collection) {
var _this4 = this;
return new Promise(function (ok, fail) {
_this4.db.collection(collection).insert(documents, function (err, result) {
return err ? fail(err) : ok(result.ops);
_this4.db.collection(collection).drop(function (err, result) {
return err ? fail(err) : ok();
});

@@ -91,9 +106,22 @@ });

}, {
key: "update",
value: function update(collection, conditions, updateOptions) {
key: "find",
value: function find(collection, conditions, options) {
var _this5 = this;
if (!options) options = {};
return new Promise(function (ok, fail) {
_this5.db.collection(collection).updateOne(conditions, updateOptions, function (err, result) {
return err ? fail(err) : ok();
var cursor = _this5.db.collection(collection).find(conditions);
if (options.skip) cursor.skip(options.skip);
if (options.limit) cursor.limit(options.limit);
if (options.comment) cursor.comment(options.comment);
if (options.min) cursor.min(options.min);
if (options.max) cursor.max(options.max);
if (options.maxScan) cursor.maxScan(options.maxScan);
if (options.batchSize) cursor.batchSize(options.batchSize);
if (options.returnKey) cursor.returnKey(options.returnKey);
if (options.readPreference) cursor.readPreference(options.readPreference);
if (options.sort) cursor.readPreference(options.sort);
if (options.snapshot) cursor.snapshot(options.snapshot);
cursor.toArray(function (err, result) {
return err ? fail(err) : ok(result);
});

@@ -103,9 +131,24 @@ });

}, {
key: "replace",
value: function replace(collection, conditions, newObject) {
key: "findOne",
value: function findOne(collection, conditions, options) {
if (!options) options = {};
options.limit = 1;
return this.find(collection, conditions, options).then(function (objects) {
return objects && objects.length ? objects[0] : null;
});
}
}, {
key: "findOneById",
value: function findOneById(collection, id, options) {
var idCondition = _defineProperty({}, this.getIdFieldName(), this.createObjectId(id));
return this.findOne(collection, idCondition, options);
}
}, {
key: "aggregate",
value: function aggregate(collection, stages, options) {
var _this6 = this;
return new Promise(function (ok, fail) {
_this6.db.collection(collection).replaceOne(conditions, newObject, function (err, result) {
return err ? fail(err) : ok(result.ops);
_this6.db.collection(collection).aggregate(stages, options, function (err, result) {
return err ? fail(err) : ok(result);
});

@@ -115,9 +158,10 @@ });

}, {
key: "remove",
value: function remove(collection, conditions) {
key: "setOneRelation",
value: function setOneRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
var _this7 = this;
return new Promise(function (ok, fail) {
_this7.db.collection(collection).remove(conditions, function (err, result) {
return err ? fail(err) : ok(result);
var conditions = { $unset: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this7.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
});

@@ -127,10 +171,10 @@ });

}, {
key: "removeById",
value: function removeById(collection, id) {
key: "setManyRelation",
value: function setManyRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
var _this8 = this;
return new Promise(function (ok, fail) {
var idCondition = _defineProperty({}, _this8.getIdFieldName(), _this8.createObjectId(id));
_this8.db.collection(collection).remove(idCondition, function (err, result) {
return err ? fail(err) : ok(result);
var conditions = { $pull: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this8.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
});

@@ -140,9 +184,10 @@ });

}, {
key: "find",
value: function find(collection, conditions, options) {
key: "unsetOneRelation",
value: function unsetOneRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
var _this9 = this;
return new Promise(function (ok, fail) {
_this9.db.collection(collection).find(conditions).toArray(function (err, result) {
return err ? fail(err) : ok(result);
var conditions = { $set: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this9.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
});

@@ -152,9 +197,10 @@ });

}, {
key: "findOne",
value: function findOne(collection, conditions, options) {
key: "unsetManyRelation",
value: function unsetManyRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
var _this10 = this;
return new Promise(function (ok, fail) {
_this10.db.collection(collection).findOne(conditions, function (err, result) {
return err ? fail(err) : ok(result);
var conditions = { $addToSet: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this10.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
});

@@ -164,10 +210,9 @@ });

}, {
key: "findById",
value: function findById(collection, id, options) {
key: "createIndex",
value: function createIndex(collection, keys, options) {
var _this11 = this;
var idCondition = _defineProperty({}, this.getIdFieldName(), this.createObjectId(id));
return new Promise(function (ok, fail) {
_this11.db.collection(collection).findOne(idCondition, function (err, result) {
return err ? fail(err) : ok(result);
_this11.db.collection(collection).createIndex(keys, options, function (err, result) {
return err ? fail(err) : ok();
});

@@ -177,105 +222,216 @@ });

}, {
key: "createObjectId",
value: function createObjectId(id) {
return new _mongodb.ObjectID(id);
}
}, {
key: "isObjectId",
value: function isObjectId(id) {
return id instanceof _mongodb.ObjectID;
}
}, {
key: "aggregate",
value: function aggregate(collection, stages) {
return this.db.collection(collection).aggregate(stages);
}
}, {
key: "getIdFieldName",
value: function getIdFieldName() {
return '_id';
}
}, {
key: "drop",
value: function drop(collection) {
key: "count",
value: function count(collection, criteria) {
var _this12 = this;
return new Promise(function (ok, fail) {
if (collection) _this12.db.collection(collection).drop(function (err, result) {
_this12.db.collection(collection).count(criteria, function (err, result) {
return err ? fail(err) : ok(result);
});else _this12.db.dropDatabase(function (err, result) {
return err ? fail(err) : ok(result);
});
});
}); // http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~countCallback
}
}, {
key: "setOneRelation",
value: function setOneRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
key: "insertOne",
value: function insertOne(collection, document, options) {
var _this13 = this;
return new Promise(function (ok, fail) {
var conditions = { $unset: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this13.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
_this13.db.collection(collection).insertOne(document, options, function (err, result) {
return err ? fail(err) : ok(result);
});
});
}
// http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~insertOneWriteOpResult
}, {
key: "setManyRelation",
value: function setManyRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
key: "insertMany",
value: function insertMany(collection, document, options) {
var _this14 = this;
return new Promise(function (ok, fail) {
var conditions = { $pull: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this14.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
_this14.db.collection(collection).insertMany(document, options, function (err, result) {
return err ? fail(err) : ok(result);
});
});
}
// http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~insertWriteOpCallback
}, {
key: "unsetOneRelation",
value: function unsetOneRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
key: "updateOne",
value: function updateOne(collection, query, update, options) {
var _this15 = this;
return new Promise(function (ok, fail) {
var conditions = { $set: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this15.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
_this15.db.collection(collection).updateOne(query, update, options, function (err, result) {
return err ? fail(err) : ok(result);
});
});
}); // http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~updateWriteOpResult
}
}, {
key: "unsetManyRelation",
value: function unsetManyRelation(collection, documentId, relationPropertyName, relationPropertyValue) {
key: "updateMany",
value: function updateMany(collection, query, update, options) {
var _this16 = this;
return new Promise(function (ok, fail) {
var conditions = { $addToSet: _defineProperty({}, relationPropertyName, relationPropertyValue) };
_this16.db.collection(collection).updateOne(conditions, null, function (err, result) {
return err ? fail(err) : ok();
_this16.db.collection(collection).updateMany(query, update, options, function (err, result) {
return err ? fail(err) : ok(result);
});
});
}); // http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~updateWriteOpResult
}
}, {
key: "createIndex",
value: function createIndex(collection, keys, options) {
key: "replaceOne",
value: function replaceOne(collection, conditions, newObject, options) {
var _this17 = this;
return new Promise(function (ok, fail) {
_this17.db.collection(collection).createIndex(keys, options, function (err, result) {
return err ? fail(err) : ok();
_this17.db.collection(collection).replaceOne(conditions, newObject, options, function (err, result) {
return err ? fail(err) : ok(result);
});
});
}
// http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~updateWriteOpResult
}, {
key: "count",
value: function count(collection, criteria) {
key: "deleteOne",
value: function deleteOne(collection, query, options) {
var _this18 = this;
return new Promise(function (ok, fail) {
_this18.db.collection(collection).count(criteria, function (err, result) {
_this18.db.collection(collection).deleteOne(query, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~deleteWriteOpResult
}
}, {
key: "deleteMany",
value: function deleteMany(collection, query, options) {
var _this19 = this;
return new Promise(function (ok, fail) {
_this19.db.collection(collection).deleteMany(query, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~deleteWriteOpResult
}
}, {
key: "deleteOneById",
value: function deleteOneById(collection, id, options) {
var _this20 = this;
return new Promise(function (ok, fail) {
var idCondition = _defineProperty({}, _this20.getIdFieldName(), _this20.createObjectId(id));
_this20.db.collection(collection).deleteOne(idCondition, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~deleteWriteOpResult
}
}, {
key: "distinct",
value: function distinct(collection, key, query, options) {
var _this21 = this;
return new Promise(function (ok, fail) {
_this21.db.collection(collection).distinct(key, query, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~resultCallback
}
}, {
key: "findOneAndDelete",
value: function findOneAndDelete(collection, query, options) {
var _this22 = this;
return new Promise(function (ok, fail) {
_this22.db.collection(collection).findOneAndDelete(query, options, function (err, result) {
return err ? fail(err) : ok(result.value);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~findAndModifyWriteOpResult
}
}, {
key: "findOneAndReplace",
value: function findOneAndReplace(collection, query, replacement, options) {
var _this23 = this;
return new Promise(function (ok, fail) {
_this23.db.collection(collection).findOneAndReplace(query, replacement, options, function (err, result) {
return err ? fail(err) : ok(result.value);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~findAndModifyWriteOpResult
}
}, {
key: "findOneAndUpdate",
value: function findOneAndUpdate(collection, query, update, options) {
var _this24 = this;
return new Promise(function (ok, fail) {
_this24.db.collection(collection).findOneAndUpdate(query, update, options, function (err, result) {
return err ? fail(err) : ok(result.value);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~findAndModifyWriteOpResult
}
}, {
key: "geoHaystackSearch",
value: function geoHaystackSearch(collection, x, y, options) {
var _this25 = this;
return new Promise(function (ok, fail) {
_this25.db.collection(collection).geoHaystackSearch(x, y, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~resultCallback
}
}, {
key: "geoNear",
value: function geoNear(collection, x, y, options) {
var _this26 = this;
return new Promise(function (ok, fail) {
_this26.db.collection(collection).geoNear(x, y, options, function (err, result) {
return err ? fail(err) : ok(result);
});
// result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~resultCallback
});
}
}, {
key: "group",
value: function group(collection, keys, condition, initial, reduce, finalize, command, options) {
var _this27 = this;
return new Promise(function (ok, fail) {
_this27.db.collection(collection).group(keys, condition, initial, reduce, finalize, command, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~resultCallback
}
}, {
key: "executeOrderedOperations",
value: function executeOrderedOperations(collection, operations, options) {
var batch = this.db.collection(collection).initializeOrderedBulkOp(options);
operations();
return new Promise(function (ok, fail) {
batch.execute(function (err, result) {
return err ? fail(err) : ok(result);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/BulkWriteResult.html
}
}, {
key: "executeUnorderedOperations",
value: function executeUnorderedOperations(collection, operations, options) {
var batch = this.db.collection(collection).initializeUnorderedBulkOp(options);
operations();
return new Promise(function (ok, fail) {
batch.execute(function (err, result) {
return err ? fail(err) : ok(result);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/BulkWriteResult.html
}
}, {
key: "mapReduce",
value: function mapReduce(collection, map, reduce, options) {
var _this28 = this;
return new Promise(function (ok, fail) {
_this28.db.collection(collection).mapReduce(map, reduce, options, function (err, result) {
return err ? fail(err) : ok(result);
});
}); // result http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#~resultCallback
}
}, {
key: "native",

@@ -282,0 +438,0 @@

{
"name": "typeodm",
"version": "0.0.6",
"version": "0.0.7",
"description": "ODM for MongoDB used Typescript",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -101,3 +101,3 @@ "use strict";

return {
v: driver.replace(schema.name, conditions, dbObject).then(function (saved) {
v: driver.replaceOne(schema.name, conditions, dbObject).then(function (saved) {
broadcaster.broadcastAfterUpdate({ document: document, conditions: conditions });

@@ -112,4 +112,4 @@ return document;

broadcaster.broadcastBeforeInsert({ document: document });
return driver.insert(schema.name, dbObject).then(function (savedDocument) {
document[schema.idField.name] = String(savedDocument[driver.getIdFieldName()]);
return driver.insertOne(schema.name, dbObject).then(function (result) {
if (result.insertedId) document[schema.idField.name] = String(result.insertedId);
broadcaster.broadcastAfterInsert({ document: document });

@@ -116,0 +116,0 @@ return document;

@@ -49,3 +49,3 @@ "use strict";

// load original document so we can compare and calculate changed set
return this.connection.driver.findById(schema.name, documentId).then(function (dbObject) {
return this.connection.driver.findOneById(schema.name, documentId).then(function (dbObject) {
if (!dbObject) throw new _exceptionNoDocumentWithSuchIdException.NoDocumentWithSuchIdException(documentId, schema.name);

@@ -81,3 +81,3 @@ // iterate throw each key in the document and find relations to compute removals of

broadcaster.broadcastBeforeRemove({ documentId: operation.id });
return _this2.connection.driver.removeById(operation.schema.name, operation.id).then(function (result) {
return _this2.connection.driver.deleteOneById(operation.schema.name, operation.id).then(function (result) {
broadcaster.broadcastAfterRemove({ documentId: operation.id });

@@ -118,3 +118,3 @@ });

// load original document so we can compare and calculate which of its relations to remove by cascades
return this.connection.driver.findById(schema.name, documentId).then(function (dbObject) {
return this.connection.driver.findOneById(schema.name, documentId).then(function (dbObject) {
if (!dbObject) throw new _exceptionNoDocumentWithSuchIdException.NoDocumentWithSuchIdException(documentId, schema.name);

@@ -121,0 +121,0 @@ // iterate throw each key in the db document and find relations to compute removals of

@@ -54,3 +54,12 @@ "use strict";

}
/**
* Checks if document has id.
*/
}, {
key: "hasId",
value: function hasId(document) {
return document && document.hasOwnProperty(this.schema.idField.name);
}
}, {
key: "initialize",

@@ -74,5 +83,5 @@ value: function initialize(json, fetchOption /*, fetchCascadeOptions?: any*/) {

return _this.dbObjectToDocument(object, joinFields);
})) : objects;
})) : [];
}).then(function (documents) {
_this.broadcaster.broadcastAfterLoadedAll(documents);
if (documents.length > 0) _this.broadcaster.broadcastAfterLoadedAll(documents);
return documents;

@@ -92,5 +101,5 @@ });

return this.connection.driver.findOne(this.schema.name, conditions, options).then(function (i) {
return i ? _this2.dbObjectToDocument(i, joinFields) : i;
return i ? _this2.dbObjectToDocument(i, joinFields) : null;
}).then(function (document) {
_this2.broadcaster.broadcastAfterLoaded(document);
if (document) _this2.broadcaster.broadcastAfterLoaded(document);
return document;

@@ -110,5 +119,5 @@ });

return this.connection.driver.findOne(this.schema.name, this.createIdObject(id), options).then(function (i) {
return i ? _this3.dbObjectToDocument(i, joinFields) : i;
return i ? _this3.dbObjectToDocument(i, joinFields) : null;
}).then(function (document) {
_this3.broadcaster.broadcastAfterLoaded(document);
if (document) _this3.broadcaster.broadcastAfterLoaded(document);
return document;

@@ -168,5 +177,4 @@ });

this.broadcaster.broadcastBeforeUpdate({ conditions: selectConditions, options: updateOptions });
return this.connection.driver.update(this.schema.name, selectConditions, updateOptions).then(function (document) {
_this5.broadcaster.broadcastAfterUpdate({ document: document, conditions: selectConditions, options: updateOptions });
return document;
return this.connection.driver.updateOne(this.schema.name, selectConditions, updateOptions).then(function (result) {
_this5.broadcaster.broadcastAfterUpdate({ conditions: selectConditions, options: updateOptions });
});

@@ -184,5 +192,4 @@ }

this.broadcaster.broadcastBeforeUpdate({ conditions: conditions, options: updateOptions });
return this.connection.driver.update(this.schema.name, conditions, updateOptions).then(function (document) {
_this6.broadcaster.broadcastAfterUpdate({ document: document, conditions: conditions, options: updateOptions });
return document;
return this.connection.driver.updateOne(this.schema.name, conditions, updateOptions).then(function (document) {
_this6.broadcaster.broadcastAfterUpdate({ conditions: conditions, options: updateOptions });
});

@@ -201,5 +208,4 @@ }

this.broadcaster.broadcastBeforeRemove({ documentId: id, conditions: conditions });
return this.connection.driver.remove(this.schema.name, conditions).then(function (result) {
return this.connection.driver.deleteOne(this.schema.name, conditions).then(function (result) {
_this7.broadcaster.broadcastAfterRemove({ documentId: id, conditions: conditions });
return document;
});

@@ -217,3 +223,3 @@ }

this.broadcaster.broadcastBeforeRemove({ conditions: conditions });
return this.connection.driver.remove(this.schema.name, conditions).then(function (document) {
return this.connection.driver.deleteOne(this.schema.name, conditions).then(function (document) {
_this8.broadcaster.broadcastAfterRemove({ conditions: conditions });

@@ -225,7 +231,40 @@ return document;

/**
* Runs aggregation steps and returns its result.
* Finds documents by given criteria and returns them with the total number of
*/
}, {
key: "findAndCount",
value: function findAndCount(criteria, findOptions, countOptions) {
var _this9 = this;
var documents = undefined;
return this.find(criteria, findOptions).then(function (loadedDocuments) {
documents = loadedDocuments;
return _this9.count(criteria, countOptions);
}).then(function (count) {
return {
documents: documents,
count: count
};
});
}
/**
* Gives number of rows found by a given criteria.
*/
}, {
key: "count",
value: function count(criteria, options) {
return this.connection.driver.count(this.schema.name, criteria, options);
}
/**
* Runs aggregation steps and returns its result. Note that result is raw mongodb objects, so you must
* process it by yourself to fit this data to your models.
*
* @param stages Array containing all the aggregation framework commands for the execution.
* @param options Optional settings.
*/
}, {
key: "aggregate",
value: function aggregate(stages) {
value: function aggregate(stages, options) {
return this.connection.driver.aggregate(this.schema.name, stages);

@@ -235,39 +274,268 @@ }

/**
* Checks if document has id.
* Runs aggregation steps and returns its result. This method supposes that documents will be returned at the
* end of aggregation operation.
*
* @param stages Array containing all the aggregation framework commands for the execution.
* @param options Optional settings.
*/
}, {
key: "hasId",
value: function hasId(document) {
return document && document.hasOwnProperty(this.schema.idField.name);
key: "aggregateDocuments",
value: function aggregateDocuments(stages, options) {
var _this10 = this;
return this.connection.driver.aggregate(this.schema.name, stages).then(function (objects) {
return Promise.all(objects.map(function (object) {
return _this10.dbObjectToDocument(object);
}));
});
}
/**
* Gives number of rows found by a given criteria.
* Inserts a single document into MongoDB.
*
* @param document Document to insert.
* @param options Optional settings.
*/
}, {
key: "count",
value: function count(criteria) {
return this.connection.driver.count(this.schema.name, criteria);
key: "insertOne",
value: function insertOne(document, options) {
var _this11 = this;
return this.connection.driver.insertOne(this.schema.name, document, options).then(function (result) {
if (result.insertedId) document[_this11.schema.idField.name] = String(result.insertedId);
});
}
/**
* Finds documents by given criteria and returns them with the total number of
* Inserts an array of documents into MongoDB.
*
* @param documents Documents to insert.
* @param options Optional settings.
*/
}, {
key: "findAndCount",
value: function findAndCount(criteria, findOptions) {
var _this9 = this;
key: "insertMany",
value: function insertMany(documents, options) {
var _this12 = this;
var documents = undefined;
return this.find(criteria, findOptions).then(function (loadedDocuments) {
documents = loadedDocuments;
return _this9.count(criteria);
}).then(function (count) {
return {
documents: documents,
count: count
};
return this.connection.driver.insertMany(this.schema.name, documents, options).then(function (result) {
return result.insertedIds.forEach(function (id, index) {
documents[index][_this12.schema.idField.name] = String(id);
});
});
}
/**
* Update a single document on MongoDB
*
* @param query The Filter used to select the document to update
* @param update The update operations to be applied to the document
* @param options Optional settings.
*/
}, {
key: "updateOne",
value: function updateOne(query, update, options) {
return this.connection.driver.updateOne(this.schema.name, query, update, options).then(function () {});
}
/**
* Update multiple documents on MongoDB
*
* @param query The Filter used to select the document to update
* @param update The update operations to be applied to the document
* @param options Optional settings.
*/
}, {
key: "updateMany",
value: function updateMany(query, update, options) {
return this.connection.driver.updateMany(this.schema.name, query, update, options).then(function () {});
}
/**
* Replace a document on MongoDB.
*
* @param query The Filter used to select the document to update
* @param document The Document that replaces the matching document
* @param options Optional settings.
*/
}, {
key: "replaceOne",
value: function replaceOne(query, document, options) {
return this.connection.driver.replaceOne(this.schema.name, query, document, options).then(function () {});
}
/**
* Delete a document on MongoDB.
*
* @param query The Filter used to select the document to remove
* @param options Optional settings.
*/
}, {
key: "deleteOne",
value: function deleteOne(query, options) {
return this.connection.driver.deleteOne(this.schema.name, query, options).then(function () {});
}
/**
* Delete multiple documents on MongoDB.
*
* @param query The Filter used to select the documents to remove
* @param options
*/
}, {
key: "deleteMany",
value: function deleteMany(query, options) {
return this.connection.driver.deleteMany(this.schema.name, query, options).then(function () {});
}
/**
* The distinct command returns returns a list of distinct values for the given key across a collection.
*
* @param key Field of the document to find distinct values for.
* @param query The query for filtering the set of documents to which we apply the distinct filter.
* @param options
*/
}, {
key: "distinct",
value: function distinct(key, query, options) {
return this.connection.driver.distinct(this.schema.name, key, query, options);
}
/**
* Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
*
* @param query Document selection filter.
* @param options Optional settings.
*/
}, {
key: "findOneAndDelete",
value: function findOneAndDelete(query, options) {
return this.connection.driver.findOneAndDelete(this.schema.name, query, options);
}
/**
* Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.
*
* @param query Document selection filter.
* @param replacement Document replacing the matching document.
* @param options Optional settings.
*/
}, {
key: "findOneAndReplace",
value: function findOneAndReplace(query, replacement, options) {
return this.connection.driver.findOneAndReplace(this.schema.name, query, replacement, options);
}
/**
* Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.
*
* @param query Document selection filter.
* @param update Update operations to be performed on the document
* @param options Optional settings.
*/
}, {
key: "findOneAndUpdate",
value: function findOneAndUpdate(query, update, options) {
return this.connection.driver.findOneAndReplace(this.schema.name, query, update, options);
}
/**
* Execute a geo search using a geo haystack index on a collection.
*
* @param x Point to search on the x axis, ensure the indexes are ordered in the same order.
* @param y Point to search on the y axis, ensure the indexes are ordered in the same order.
* @param options Optional settings.
*/
}, {
key: "geoHaystackSearch",
value: function geoHaystackSearch(x, y, options) {
return this.connection.driver.geoHaystackSearch(this.schema.name, x, y, options);
}
/**
* Execute the geoNear command to search for items in the collection.
*
* @param x Point to search on the x axis, ensure the indexes are ordered in the same order.
* @param y Point to search on the y axis, ensure the indexes are ordered in the same order.
* @param options Optional settings.
*/
}, {
key: "geoNear",
value: function geoNear(x, y, options) {
return this.connection.driver.geoHaystackSearch(this.schema.name, x, y, options);
}
/**
* Run a group command across a collection.
*
* @param keys An object, array or function expressing the keys to group by.
* @param condition An optional condition that must be true for a row to be considered.
* @param initial Initial value of the aggregation counter object.
* @param reduce The reduce function aggregates (reduces) the objects iterated
* @param finalize An optional function to be run on each item in the result set just before the item is returned.
* @param command Specify if you wish to run using the internal group command or using eval, default is true.
* @param options Optional settings.
*/
}, {
key: "group",
value: function group(keys, condition, initial, reduce, finalize, command, options) {
return this.connection.driver.group(this.schema.name, keys, condition, initial, reduce, finalize, command, options);
}
/**
* Initiate an In order bulk write operation .
*
* @param operations Function where all operations are being runned
* @param options Optional settings.
*/
}, {
key: "executeOrderedOperations",
value: function executeOrderedOperations(operations, options) {
return this.connection.driver.executeOrderedOperations(this.schema.name, operations, options).then(function () {});
}
/**
* Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove
* commands executed out of order.
*
* @param operations Function where all operations are being runned
* @param options Optional settings.
*/
}, {
key: "executeUnorderedOperations",
value: function executeUnorderedOperations(operations, options) {
return this.connection.driver.executeUnorderedOperations(this.schema.name, operations, options).then(function () {});
}
/**
* Run Map Reduce across a collection.
*
* @param map The mapping function.
* @param reduce The reduce function.
* @param options Optional settings.
*/
}, {
key: "mapReduce",
value: function mapReduce(map, reduce, options) {
return this.connection.driver.mapReduce(this.schema.name, map, reduce, options);
}
/**
* Run Map Reduce across a collection. The resulted value must be document objects.
*
* @param map The mapping function.
* @param reduce The reduce function.
* @param options Optional settings.
*/
}, {
key: "mapReduceDocument",
value: function mapReduceDocument(map, reduce, options) {
var _this13 = this;
return this.connection.driver.mapReduce(this.schema.name, map, reduce, options).then(function (results) {
return results && results.length ? results.map(function (i) {
return _this13.dbObjectToDocument(i);
}) : null;
});
}
// -------------------------------------------------------------------------

@@ -274,0 +542,0 @@ // Private Methods

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc