Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Remove attributes #45

Closed
Toobian opened this issue Jun 11, 2015 · 4 comments
Closed

Remove attributes #45

Toobian opened this issue Jun 11, 2015 · 4 comments

Comments

@Toobian
Copy link

Toobian commented Jun 11, 2015

How can i do to remove attribute ?
i create temporary attributes like token to recover password. But after used this attribute i want to remove from my Document.
I see nothing in set method which remove attribute if nothing is passed or null value...

@vadimdemedes
Copy link
Owner

As a workaround, you can:

delete post.attributes.title;
yield* post.save();

Thanks for suggestion, I will add remove() or unset() method.

@Toobian
Copy link
Author

Toobian commented Jun 16, 2015

Thanks for solution :)

@Toobian Toobian closed this as completed Jun 16, 2015
@Toobian Toobian reopened this Jun 16, 2015
@achrome
Copy link

achrome commented Jul 23, 2015

The way I have dealt with this is the following. I'm thinking that this might also work on the core Model

export default class User extends Model {
  configure() {
    this.privateFields = ['password', 'created_at', 'updated_at'];
  }
  filter() {
    return R.omit(this.privateFields, this.attributes); // R is an instance of ramda.js
  }
  toJSON() {
    return this.filter();
  }
}

Let me dig around the source and see if I can create a PR if this sounds good.

@vadimdemedes
Copy link
Owner

Added unset() method, usage:

user.unset('email');
post.unset('author.name');

Available on npm as mongorito@1.3.4.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants