Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle specifying index along with sparse/unique option

closes #1004
  • Loading branch information...
commit 585e736ca7bfa4ab24754757837ad8f4e8602142 1 parent 4ef28d5
@aheckmann aheckmann authored
Showing with 14 additions and 0 deletions.
  1. +3 −0  lib/schematype.js
  2. +11 −0 test/schema.type.test.js
View
3  lib/schematype.js
@@ -23,6 +23,9 @@ function SchemaType (path, options, instance) {
this.selected;
for (var i in options) if (this[i] && 'function' == typeof this[i]) {
+ // { unique: true, index: true }
+ if ('index' == i && this._index) continue;
+
var opts = Array.isArray(options[i])
? options[i]
: [options[i]];
View
11 test/schema.type.test.js
@@ -15,4 +15,15 @@ describe('schematype', function(){
var a = new Schema({ thought: { type: String, select: true }});
assert.equal(true, a.path('thought').selected);
})
+
+ it('properly handles specifying index in combination with unique or sparse', function(){
+ var s = new Schema({ name: { type: String, index: true, unique: true }});
+ assert.deepEqual(s.path('name')._index, { unique: true });
+ var s = new Schema({ name: { type: String, unique: true, index: true }});
+ assert.deepEqual(s.path('name')._index, { unique: true });
+ var s = new Schema({ name: { type: String, index: true, sparse: true }});
+ assert.deepEqual(s.path('name')._index, { sparse: true });
+ var s = new Schema({ name: { type: String, sparse: true, index: true }});
+ assert.deepEqual(s.path('name')._index, { sparse: true });
+ })
})
Please sign in to comment.
Something went wrong with that request. Please try again.