Add new collation methods for mongoose (#16897)

* Add collation methods for query and aggregation

* Add tests for collation
This commit is contained in:
Simon Xiong
2017-06-01 13:22:14 -04:00
committed by Mohamed Hegazy
parent ea7b301f5d
commit c85fe6ae3f
2 changed files with 19 additions and 0 deletions

View File

@@ -1417,6 +1417,9 @@ declare module "mongoose" {
circle(area: Object): this;
circle(path: string, area: Object): this;
/** Adds a collation to this op (MongoDB 3.4 and up) */
collation(value: CollationOptions): this;
/** Specifies the comment option. Cannot be used with distinct() */
comment(val: string): this;
@@ -1817,6 +1820,17 @@ declare module "mongoose" {
context?: string;
}
interface CollationOptions {
locale?: string;
caseLevel?: boolean;
caseFirst?: string;
strength?: number;
numericOrdering?: boolean;
alternate?: string;
maxVariable?: string;
backwards?: boolean;
}
namespace Schema {
namespace Types {
/*
@@ -2089,6 +2103,9 @@ declare module "mongoose" {
*/
append(...ops: Object[]): this;
/** Adds a collation. */
collation(options: CollationOptions): this;
/**
* Sets the cursor option option for the aggregation query (ignored for < 2.6.0).
* Note the different syntax below: .exec() returns a cursor object, and no callback

View File

@@ -660,6 +660,7 @@ query.catch(cb).catch(cb);
query.center({}).center({});
query.centerSphere({ center: [50, 50], radius: 10 }).centerSphere('path', {});
query.circle({ center: [50, 50], radius: 10 }).circle('path');
query.collation({ locale: 'en_US', strength: 1 });
query.comment('comment').comment('comment');
query.where({color: 'black'}).count(function (err, count) {
count.toFixed();
@@ -995,6 +996,7 @@ aggregate.addCursorFlag('flag', true).addCursorFlag('', false);
aggregate.allowDiskUse(true).allowDiskUse(false, []);
aggregate.append({ $project: { field: 1 }}, { $limit: 2 });
aggregate.append([{ $match: { daw: 'Logic Audio X' }} ]);
aggregate.collation({ locale: 'en_US', strength: 1 });
aggregate.cursor({ batchSize: 1000 }).exec().each(cb);
aggregate.exec().then(cb).catch(cb);
aggregate.explain(cb).then(cb).catch(cb);