> For the complete documentation index, see [llms.txt](https://sebloix.gitbook.io/gstore-node/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sebloix.gitbook.io/gstore-node/v8.x/model/methods/sanitize.md).

# sanitize()

This methods will clean and do basic formatting of an entity data. You should always execute it on data coming from an untrusted source. MyModel.sanitize() will:

* **remove properties** that are marked as **not writable** in schemas
* convert 'null' (string) values to **null**
* convert entity **refs** that have been populated back to their Datastore Key

```javascript
// user.model.js

const userSchema = new Schema({
    name : { type: String },
    createdOn : { type: Date, write: false } // write is not allowed
});

// or with a Joi schema
const schema = new Schema({
    name: { joi: Joi.string() },
    createdOn: { joi: Joi.date().strip() } // strip() will remove the property when Sanitizing
}, { joi: true });

module.exports = gstore.model('User', userSchema);
```

```javascript
// user.controller.js
const User = require('./user.model');

let data = req.body;
console.log(data);
/*
{
    createdOn: '2016-03-01T21:30:00',
    name: 'null',
    propertyNotDefined: 'abcdef',
}
*/

// Now sanitize the body request
data = User.sanitize(req.body);
console.log(data);

/*
{
    name: null,
}
*/
```
