Skip to content

Commit cd783aa

Browse files
committed
added tags for promoteValues/promoteLong/raw to find/findOne and aggregate
1 parent 96d6d3a commit cd783aa

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/collection.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,13 +1361,14 @@ define.classMethod('save', {callback: true, promise:true});
13611361
* @param {number} [options.max=null] Set index bounds.
13621362
* @param {boolean} [options.showDiskLoc=false] Show disk location of results.
13631363
* @param {string} [options.comment=null] You can put a $comment field on a query to make looking in the profiler logs simpler.
1364-
* @param {boolean} [options.raw=false] Return all BSON documents as Raw Buffer documents.
1364+
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
1365+
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
1366+
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
13651367
* @param {(ReadPreference|string)} [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
13661368
* @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
13671369
* @param {number} [options.maxTimeMS=null] Number of miliseconds to wait before aborting the query.
13681370
* @param {Collection~resultCallback} [callback] The command result callback
13691371
* @return {Promise} returns Promise if no callback passed
1370-
* @deprecated use find().limit(1).next(function(err, doc){})
13711372
*/
13721373
Collection.prototype.findOne = function() {
13731374
var self = this;
@@ -2554,6 +2555,9 @@ function decorateWithCollation(command, self, options) {
25542555
* @param {boolean} [options.allowDiskUse=false] allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 >).
25552556
* @param {number} [options.maxTimeMS=null] maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
25562557
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
2558+
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
2559+
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
2560+
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
25572561
* @param {Collection~resultCallback} callback The command result callback
25582562
* @return {(null|AggregationCursor)}
25592563
*/

test/functional/promote_values_tests.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,40 @@ exports['should correctly honor promoteValues at cursor find level'] = {
147147
});
148148
}
149149
}
150+
151+
exports['should correctly honor promoteValues at aggregate level'] = {
152+
// Add a tag that our runner can trigger on
153+
// in this case we are setting that node needs to be higher than 0.10.X to run
154+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
155+
156+
// The actual test we wish to run
157+
test: function(configuration, test) {
158+
var Long = configuration.require.Long,
159+
Int32 = configuration.require.Int32,
160+
Double = configuration.require.Double,
161+
MongoClient = configuration.require.MongoClient;
162+
163+
MongoClient.connect(configuration.url(), {
164+
}, function(err, db) {
165+
db.collection('shouldCorrectlyHonorPromoteValues2').insert({
166+
doc: Long.fromNumber(10)
167+
, int: 10
168+
, double: 2.2222
169+
, array: [[Long.fromNumber(10)]]
170+
}, function(err, doc) {
171+
test.equal(null, err);
172+
173+
db.collection('shouldCorrectlyHonorPromoteValues2').aggregate([{$match: {}}], {promoteValues: false}).next(function(err, doc) {
174+
test.equal(null, err);
175+
176+
test.deepEqual(Long.fromNumber(10), doc.doc);
177+
test.deepEqual(new Int32(10), doc.int);
178+
test.deepEqual(new Double(2.2222), doc.double);
179+
180+
db.close();
181+
test.done();
182+
});
183+
});
184+
});
185+
}
186+
}

0 commit comments

Comments
 (0)