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

Idea: Save only properties defined in schema #221

Open
MR4online opened this issue Nov 29, 2023 · 1 comment
Open

Idea: Save only properties defined in schema #221

MR4online opened this issue Nov 29, 2023 · 1 comment

Comments

@MR4online
Copy link

hi, there!

Is it possible to save only the in the schema defined properties?
Or to define properties, that will not be saved in redis?

Example:

Schema:

const test = new Schema("test", {
    uuid: {type: "string"}
});

and then I save data:

testRepository.save({ "uuid": 123, "user-language":"en" });

will result in having both properties (uuid and user-language) in the redis json object.

Currently it looks like i have to do this manually,
but I like to keep the Data on the Object to use it later.
so I would need to do something like:

const userLang = data["user-language"];
data["user-language"] = undefined;
data = testRepository.save({ "uuid": 123, "user-language":"en" });
data["user-language"] = userLang;

with multiple Properties or Objects as Properties, this is :-(

Idea:

const test = new Schema("test", {
    uuid: {type: "string"}
}, { saveSchemaOnly: true });

(which would be a simple solution to avoid saving unwanted data for unexperienced user as well)
or

const test = new Schema("test", {
    uuid: {type: "string"},
    foo: {ignore: true}
});

Thanks.

@Didas-git
Copy link
Contributor

This would be simple to implement actually, and its honestly the best way to go about it, saving things that arent defined on the schema usually isnt a great idea.
However this was done because people have asked to be able to save anything even if not defined on the schema, i would also like to see an option for this like strict: true.

In short: +1 on this

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

No branches or pull requests

2 participants