summaryrefslogtreecommitdiff
path: root/src/mongo/shell/crud_api.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/shell/crud_api.js')
-rw-r--r--src/mongo/shell/crud_api.js296
1 files changed, 148 insertions, 148 deletions
diff --git a/src/mongo/shell/crud_api.js b/src/mongo/shell/crud_api.js
index bcd245f4878..dd7d334291a 100644
--- a/src/mongo/shell/crud_api.js
+++ b/src/mongo/shell/crud_api.js
@@ -30,7 +30,7 @@ DBCollection.prototype.addIdIfNeeded = function(obj) {
if (typeof obj !== "object") {
throw new Error('argument passed to addIdIfNeeded is not an object');
}
- if (typeof(obj._id) == "undefined" && !Array.isArray(obj)) {
+ if (typeof (obj._id) == "undefined" && !Array.isArray(obj)) {
var tmp = obj; // don't want to modify input
obj = {_id: new ObjectId()};
@@ -45,32 +45,32 @@ DBCollection.prototype.addIdIfNeeded = function(obj) {
};
/**
-* Perform a bulkWrite operation without a fluent API
-*
-* Legal operation types are
-*
-* { insertOne: { document: { a: 1 } } }
-*
-* { updateOne: { filter: {a:2}, update: {$set: {"a.$[i]":2}}, upsert:true, collation: {locale:
-* "fr"}, arrayFilters: [{i: 0}] } }
-*
-* { updateMany: { filter: {a:2}, update: {$set: {"a.$[i]":2}}, upsert:true collation: {locale:
-* "fr"}, arrayFilters: [{i: 0}] } }
-*
-* { deleteOne: { filter: {c:1}, collation: {locale: "fr"} } }
-*
-* { deleteMany: { filter: {c:1}, collation: {locale: "fr"} } }
-*
-* { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true, collation: {locale: "fr"} } }
-*
-* @method
-* @param {object[]} operations Bulk operations to perform.
-* @param {object} [options=null] Optional settings.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Perform a bulkWrite operation without a fluent API
+ *
+ * Legal operation types are
+ *
+ * { insertOne: { document: { a: 1 } } }
+ *
+ * { updateOne: { filter: {a:2}, update: {$set: {"a.$[i]":2}}, upsert:true, collation: {locale:
+ * "fr"}, arrayFilters: [{i: 0}] } }
+ *
+ * { updateMany: { filter: {a:2}, update: {$set: {"a.$[i]":2}}, upsert:true collation: {locale:
+ * "fr"}, arrayFilters: [{i: 0}] } }
+ *
+ * { deleteOne: { filter: {c:1}, collation: {locale: "fr"} } }
+ *
+ * { deleteMany: { filter: {c:1}, collation: {locale: "fr"} } }
+ *
+ * { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true, collation: {locale: "fr"} } }
+ *
+ * @method
+ * @param {object[]} operations Bulk operations to perform.
+ * @param {object} [options=null] Optional settings.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.bulkWrite = function(operations, options) {
var opts = Object.extend({}, options || {});
opts.ordered = (typeof opts.ordered == 'boolean') ? opts.ordered : true;
@@ -221,16 +221,16 @@ DBCollection.prototype.bulkWrite = function(operations, options) {
};
/**
-* Inserts a single document into MongoDB.
-*
-* @method
-* @param {object} doc Document to insert.
-* @param {object} [options=null] Optional settings.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Inserts a single document into MongoDB.
+ *
+ * @method
+ * @param {object} doc Document to insert.
+ * @param {object} [options=null] Optional settings.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.insertOne = function(document, options) {
var opts = Object.extend({}, options || {});
@@ -276,17 +276,17 @@ DBCollection.prototype.insertOne = function(document, options) {
};
/**
-* Inserts an array of documents into MongoDB.
-*
-* @method
-* @param {object[]} docs Documents to insert.
-* @param {object} [options=null] Optional settings.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @param {boolean} [options.ordered=true] Execute inserts in ordered or unordered fashion.
-* @return {object}
-*/
+ * Inserts an array of documents into MongoDB.
+ *
+ * @method
+ * @param {object[]} docs Documents to insert.
+ * @param {object} [options=null] Optional settings.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @param {boolean} [options.ordered=true] Execute inserts in ordered or unordered fashion.
+ * @return {object}
+ */
DBCollection.prototype.insertMany = function(documents, options) {
var opts = Object.extend({}, options || {});
opts.ordered = (typeof opts.ordered == 'boolean') ? opts.ordered : true;
@@ -327,16 +327,16 @@ DBCollection.prototype.insertMany = function(documents, options) {
};
/**
-* Delete a document on MongoDB
-*
-* @method
-* @param {object} filter The filter used to select the document to remove
-* @param {object} [options=null] Optional settings.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Delete a document on MongoDB
+ *
+ * @method
+ * @param {object} filter The filter used to select the document to remove
+ * @param {object} [options=null] Optional settings.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.deleteOne = function(filter, options) {
var opts = Object.extend({}, options || {});
@@ -384,16 +384,16 @@ DBCollection.prototype.deleteOne = function(filter, options) {
};
/**
-* Delete multiple documents on MongoDB
-*
-* @method
-* @param {object} filter The Filter used to select the documents to remove
-* @param {object} [options=null] Optional settings.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Delete multiple documents on MongoDB
+ *
+ * @method
+ * @param {object} filter The Filter used to select the documents to remove
+ * @param {object} [options=null] Optional settings.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.deleteMany = function(filter, options) {
var opts = Object.extend({}, options || {});
@@ -441,18 +441,18 @@ DBCollection.prototype.deleteMany = function(filter, options) {
};
/**
-* Replace a document on MongoDB
-*
-* @method
-* @param {object} filter The Filter used to select the document to update
-* @param {object} doc The Document that replaces the matching document
-* @param {object} [options=null] Optional settings.
-* @param {boolean} [options.upsert=false] Update operation is an upsert.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Replace a document on MongoDB
+ *
+ * @method
+ * @param {object} filter The Filter used to select the document to update
+ * @param {object} doc The Document that replaces the matching document
+ * @param {object} [options=null] Optional settings.
+ * @param {boolean} [options.upsert=false] Update operation is an upsert.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.replaceOne = function(filter, replacement, options) {
var opts = Object.extend({}, options || {});
@@ -521,18 +521,18 @@ DBCollection.prototype.replaceOne = function(filter, replacement, options) {
};
/**
-* Update a single document on MongoDB
-*
-* @method
-* @param {object} filter The Filter used to select the document to update
-* @param {object} update The update operations to be applied to the document
-* @param {object} [options=null] Optional settings.
-* @param {boolean} [options.upsert=false] Update operation is an upsert.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Update a single document on MongoDB
+ *
+ * @method
+ * @param {object} filter The Filter used to select the document to update
+ * @param {object} update The update operations to be applied to the document
+ * @param {object} [options=null] Optional settings.
+ * @param {boolean} [options.upsert=false] Update operation is an upsert.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.updateOne = function(filter, update, options) {
var opts = Object.extend({}, options || {});
@@ -607,18 +607,18 @@ DBCollection.prototype.updateOne = function(filter, update, options) {
};
/**
-* Update multiple documents on MongoDB
-*
-* @method
-* @param {object} filter The Filter used to select the document to update
-* @param {object} update The update operations to be applied to the document
-* @param {object} [options=null] Optional settings.
-* @param {boolean} [options.upsert=false] Update operation is an upsert.
-* @param {(number|string)} [options.w=null] The write concern.
-* @param {number} [options.wtimeout=null] The write concern timeout.
-* @param {boolean} [options.j=false] Specify a journal write concern.
-* @return {object}
-*/
+ * Update multiple documents on MongoDB
+ *
+ * @method
+ * @param {object} filter The Filter used to select the document to update
+ * @param {object} update The update operations to be applied to the document
+ * @param {object} [options=null] Optional settings.
+ * @param {boolean} [options.upsert=false] Update operation is an upsert.
+ * @param {(number|string)} [options.w=null] The write concern.
+ * @param {number} [options.wtimeout=null] The write concern timeout.
+ * @param {boolean} [options.j=false] Specify a journal write concern.
+ * @return {object}
+ */
DBCollection.prototype.updateMany = function(filter, update, options) {
var opts = Object.extend({}, options || {});
@@ -693,18 +693,18 @@ DBCollection.prototype.updateMany = function(filter, update, options) {
};
/**
-* Find a document and delete it in one atomic operation,
-* requires a write lock for the duration of the operation.
-*
-* @method
-* @param {object} filter Document selection filter.
-* @param {object} [options=null] Optional settings.
-* @param {object} [options.projection=null] Limits the fields to return for all matching documents.
-* @param {object} [options.sort=null] Determines which document the operation modifies if the query
-*selects multiple documents.
-* @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
-* @return {object}
-*/
+ * Find a document and delete it in one atomic operation,
+ * requires a write lock for the duration of the operation.
+ *
+ * @method
+ * @param {object} filter Document selection filter.
+ * @param {object} [options=null] Optional settings.
+ * @param {object} [options.projection=null] Limits the fields to return for all matching documents.
+ * @param {object} [options.sort=null] Determines which document the operation modifies if the query
+ *selects multiple documents.
+ * @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
+ * @return {object}
+ */
DBCollection.prototype.findOneAndDelete = function(filter, options) {
var opts = Object.extend({}, options || {});
// Set up the command
@@ -739,22 +739,22 @@ DBCollection.prototype.findOneAndDelete = function(filter, options) {
};
/**
-* Find a document and replace it in one atomic operation, requires a write lock for the duration of
-*the operation.
-*
-* @method
-* @param {object} filter Document selection filter.
-* @param {object} replacement Document replacing the matching document.
-* @param {object} [options=null] Optional settings.
-* @param {object} [options.projection=null] Limits the fields to return for all matching documents.
-* @param {object} [options.sort=null] Determines which document the operation modifies if the query
-*selects multiple documents.
-* @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
-* @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
-* @param {boolean} [options.returnNewDocument=false] When true, returns the updated document rather
-*than the original. The default is false.
-* @return {object}
-*/
+ * Find a document and replace it in one atomic operation, requires a write lock for the duration of
+ *the operation.
+ *
+ * @method
+ * @param {object} filter Document selection filter.
+ * @param {object} replacement Document replacing the matching document.
+ * @param {object} [options=null] Optional settings.
+ * @param {object} [options.projection=null] Limits the fields to return for all matching documents.
+ * @param {object} [options.sort=null] Determines which document the operation modifies if the query
+ *selects multiple documents.
+ * @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
+ * @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
+ * @param {boolean} [options.returnNewDocument=false] When true, returns the updated document rather
+ *than the original. The default is false.
+ * @return {object}
+ */
DBCollection.prototype.findOneAndReplace = function(filter, replacement, options) {
var opts = Object.extend({}, options || {});
@@ -805,22 +805,22 @@ DBCollection.prototype.findOneAndReplace = function(filter, replacement, options
};
/**
-* Find a document and update it in one atomic operation, requires a write lock for the duration of
-*the operation.
-*
-* @method
-* @param {object} filter Document selection filter.
-* @param {object} update Update operations to be performed on the document
-* @param {object} [options=null] Optional settings.
-* @param {object} [options.projection=null] Limits the fields to return for all matching documents.
-* @param {object} [options.sort=null] Determines which document the operation modifies if the query
-*selects multiple documents.
-* @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
-* @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
-* @param {boolean} [options.returnNewDocument=false] When true, returns the updated document rather
-*than the original. The default is false.
-* @return {object}
-*/
+ * Find a document and update it in one atomic operation, requires a write lock for the duration of
+ *the operation.
+ *
+ * @method
+ * @param {object} filter Document selection filter.
+ * @param {object} update Update operations to be performed on the document
+ * @param {object} [options=null] Optional settings.
+ * @param {object} [options.projection=null] Limits the fields to return for all matching documents.
+ * @param {object} [options.sort=null] Determines which document the operation modifies if the query
+ *selects multiple documents.
+ * @param {number} [options.maxTimeMS=null] The maximum amount of time to allow the query to run.
+ * @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
+ * @param {boolean} [options.returnNewDocument=false] When true, returns the updated document rather
+ *than the original. The default is false.
+ * @return {object}
+ */
DBCollection.prototype.findOneAndUpdate = function(filter, update, options) {
var opts = Object.extend({}, options || {});