balderdashy / balderdashy/sails

Unique property throws error when using mongo

Open
#4,613 17 comments 0 reactions 0 assignees View on GitHub
orm repro please standalone waterline
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Waterline version**:0.13.6
**Node version**:10.12.0
**NPM version**:6.4.1
**Operating system**:Ubuntu 18.10


Related to - https://github.com/balderdashy/waterline/issues/1541, but no advice was given.

Currently trying to run the following code with sails-mongo. Have also tried with sails-disk and sails-memory and it is giving the same issue.

The following code results in the error: `the attribute `email` on the `user` model contains invalid properties. The property `unique` isn't a recognized property.`

```
export const userCollection = Waterline.Collection.extend({
identity: 'user',
datastore: 'default',
primaryKey: 'id',
dontUseObjectIds: true,

attributes: {
id: {
type: 'string',
required: true
},
firstName: {type: 'string'},
lastName: {type: 'string'},
email: {type: 'string', required: true, unique: true}
password: {type: 'string', required: true},

roles: {
collection: 'role'
}
}
}

```

```

const sailsMongoAdapter = require('sails-mongo');

export const datastoreConfig = {
adapters: {
'mongo': sailsMongoAdapter
},

datastores: {
default: {
adapter: 'mongo',
url: 'mongodb://mongo:27017/db',
schema:true
}
},
};

```

```

waterline.initialize(datastoreConfig, (err, ontology)=> {
if (err) {
console.error(err);
throw err;
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the Waterline.Collection.extend model definition and the waterline.initialize call shown in the report, then reproduce the validation error with the stated versions and configuration. Compare the behavior across sails-mongo, sails-disk, and sails-memory; done means the reported valid property is either accepted consistently or the issue is narrowed to a documented incompatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.