Skip to content

Commit faabdbb

Browse files
committed
docs(schema): clarify that uppercase, lowercase, and trim options for SchemaString don't affect RegExp queries
Fix #8333
1 parent 4df0a3c commit faabdbb

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

lib/schema/string.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ SchemaString.prototype.enum = function() {
232232
* console.log(m.email) // [email protected]
233233
* M.find({ email: 'SomeEmail@example.com' }); // Queries by '[email protected]'
234234
*
235+
* Note that `lowercase` does **not** affect regular expression queries:
236+
*
237+
* ####Example:
238+
* // Still queries for documents whose `email` matches the regular
239+
* // expression /SomeEmail/. Mongoose does **not** convert the RegExp
240+
* // to lowercase.
241+
* M.find({ email: /SomeEmail/ });
242+
*
235243
* @api public
236244
* @return {SchemaType} this
237245
*/
@@ -262,6 +270,12 @@ SchemaString.prototype.lowercase = function(shouldApply) {
262270
* console.log(m.caps) // AN EXAMPLE
263271
* M.find({ caps: 'an example' }) // Matches documents where caps = 'AN EXAMPLE'
264272
*
273+
* Note that `uppercase` does **not** affect regular expression queries:
274+
*
275+
* ####Example:
276+
* // Mongoose does **not** convert the RegExp to uppercase.
277+
* M.find({ email: /an example/ });
278+
*
265279
* @api public
266280
* @return {SchemaType} this
267281
*/
@@ -288,12 +302,21 @@ SchemaString.prototype.uppercase = function(shouldApply) {
288302
*
289303
* ####Example:
290304
*
291-
* var s = new Schema({ name: { type: String, trim: true }})
292-
* var M = db.model('M', s)
293-
* var string = ' some name '
294-
* console.log(string.length) // 11
295-
* var m = new M({ name: string })
296-
* console.log(m.name.length) // 9
305+
* var s = new Schema({ name: { type: String, trim: true }});
306+
* var M = db.model('M', s);
307+
* var string = ' some name ';
308+
* console.log(string.length); // 11
309+
* var m = new M({ name: string });
310+
* console.log(m.name.length); // 9
311+
*
312+
* // Equivalent to `findOne({ name: string.trim() })`
313+
* M.findOne({ name: string });
314+
*
315+
* Note that `trim` does **not** affect regular expression queries:
316+
*
317+
* ####Example:
318+
* // Mongoose does **not** trim whitespace from the RegExp.
319+
* M.find({ name: / some name / });
297320
*
298321
* @api public
299322
* @return {SchemaType} this

0 commit comments

Comments
 (0)