Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document strictObjectIDCorecion flag #379

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,66 @@ make benchmarks

The results will be output in `./benchmarks/results.md`.

## strictObjectIDCoercion flag

In version 1.17.0, the id of string type is being converted to ObjectID, when the string length is 12 or 24 and has the format of an ObjectID i.e /^[0-9a-fA-F]{24}$/. To avoid this issue, the strictObjectIDCoercion flag should be set to true in the model-definition file.

model-definition.js

```js
{
"name": "myModelName",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true,
"strictObjectIDCoercion": true
},
...
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have an example boot script to go with it?

@loay You can use the same example as I used for this issue

boot-script.js

```js
'use strict';
var util = require('util');

module.exports = function(app) {
var db = app.dataSources.mongoDs;
var myModelName = app.models.myModelName;

db.automigrate(function(err) {
if (err) throw err;
console.log('Automigrate complete');

myModelName.create([{
id: '59460487e9532ae90c324b59',
name: 'Bob',
}, {
id: '59460487e9532ae90c324b5a',
name: 'Sam',
}, {
id: '420',
name: 'Foo',
age: 1,
}, {
id: '21',
name: 'Bar',
}], function(err, result) {
if (err) throw err;
console.log('\nCreated instances of myModelName: ' + util.inspect(result, 4));

myModelName.find({where: {id: {inq: ['59460487e9532ae90c324b59',
'59460487e9532ae90c324b5a']}}},
function(err, result) {
if (err) throw err;
console.log('\nFound instance with inq: ' + util.inspect(result, 4));
});
});
});
};
```

## Release notes

* 1.1.7 - Do not return MongoDB-specific _id to client API, except if specifically specified in the model definition