Skip to content

Commit

Permalink
revert(collection): reverting collection-mapping features
Browse files Browse the repository at this point in the history
Reverts #1698. With mongodb/js-bson#253 and other approaches to
document-class mapping on the table, we'd like to have further
discussion before committing to any one API approach.

Reopens NODE-1450
  • Loading branch information
daprahamian authored Jun 25, 2018
1 parent 5a9fdf0 commit 7298c76
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 385 deletions.
9 changes: 0 additions & 9 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,6 @@ Collection.prototype.find = function(query, options, callback) {

const cursor = this.s.topology.cursor(this.s.namespace, findCommand, newOptions);

// automatically call map on the cursor if the map option is set
if (typeof this.s.options.map === 'function') {
cursor.map(this.s.options.map);
}

return typeof callback === 'function' ? handleCallback(callback, null, cursor) : cursor;
};

Expand Down Expand Up @@ -756,10 +751,6 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
options.ignoreUndefined = this.s.options.ignoreUndefined;
}

if (typeof this.s.options.unmap === 'function') {
doc = this.s.options.unmap(doc);
}

return executeOperation(this.s.topology, replaceOne, [this, filter, doc, options, callback]);
};

Expand Down
2 changes: 0 additions & 2 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ const collectionKeys = [
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
* @param {boolean} [options.strict=false] Returns an error if the collection does not exist
* @param {function} [options.map] Function to map documents returned in find, findOne, and findAndModify commands.
* @param {function} [options.unmap] Function to unmap documents passed to insertOne, insertMany, and replaceOne commands.
* @param {object} [options.readConcern=null] Specify a read concern for the collection. (only MongoDB 3.2 or higher supported)
* @param {object} [options.readConcern.level='local'] Specify a read concern level for the collection operations, one of [local|majority]. (only MongoDB 3.2 or higher supported)
* @param {Db~collectionResultCallback} [callback] The collection result callback
Expand Down
11 changes: 2 additions & 9 deletions lib/operations/collection_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,6 @@ function findAndModify(coll, query, sort, doc, options, callback) {
executeCommand(coll.s.db, queryObject, finalOptions, (err, result) => {
if (err) return handleCallback(callback, err, null);

if (result && result.value && typeof coll.s.options.map === 'function') {
result.value = coll.s.options.map(result.value);
}

return handleCallback(callback, null, result);
});
}
Expand Down Expand Up @@ -1046,11 +1042,8 @@ function prepareDocs(coll, docs, options) {
? options.forceServerObjectId
: coll.s.db.options.forceServerObjectId;

const unmap = typeof coll.s.options.unmap === 'function' ? coll.s.options.unmap : false;

// no need to modify the docs if server sets the ObjectId
// and unmap collection option is unset
if (forceServerObjectId === true && !unmap) {
if (forceServerObjectId === true) {
return docs;
}

Expand All @@ -1059,7 +1052,7 @@ function prepareDocs(coll, docs, options) {
doc._id = coll.s.pkFactory.createPk();
}

return unmap ? unmap(doc) : doc;
return doc;
});
}

Expand Down
Loading

0 comments on commit 7298c76

Please sign in to comment.