You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Awesome job on mongoose-keywords and all the other plugins you made for your rest api generator (querymen and bodymen are just... Waw 😃 )
But right now, in spite of all the awesomeness you've put in this, I'm getting stuck trying to get keywords from an array of objects that's inside my schema, here is some JSON of an object that I'd like to get keywords for:
I would like John's "keywords" field to be generated with ['john', 'bird', 'dog']. I tried many things like creating a petSchema but keywords get created inside pets objects and it seems like I can't access them because they are part of an object in an array.
Any clue would be really helpful since I couldn't find any on the Internet, I've been stuck for hours on this and that's the only blocking element that I met so far
Thanks for reading all of this, I hope my bad english is not making it too hard to understand :c
And of course, thanks for your help whenever you answer this 😄
The text was updated successfully, but these errors were encountered:
I was able to find away around this. It's not full-proof, but worked for my use case and may work for yours.
The transform function runs on every item in the "paths" array. You can check if the value is an object and then return the property off that object you want.
Here's some sample code:
SchemaNameHere.plugin(mongooseKeywords, {
paths: ["name", "pets"],
transform: value => {
if (typeof value == "object" && value.hasOwnProperty("kind")) {
return value.kind;
}
return value;
}
});
That would save something like the following in the database:
Hi dude,
Awesome job on mongoose-keywords and all the other plugins you made for your rest api generator (querymen and bodymen are just... Waw 😃 )
But right now, in spite of all the awesomeness you've put in this, I'm getting stuck trying to get keywords from an array of objects that's inside my schema, here is some JSON of an object that I'd like to get keywords for:
I would like John's "keywords" field to be generated with ['john', 'bird', 'dog']. I tried many things like creating a petSchema but keywords get created inside pets objects and it seems like I can't access them because they are part of an object in an array.
Any clue would be really helpful since I couldn't find any on the Internet, I've been stuck for hours on this and that's the only blocking element that I met so far
Thanks for reading all of this, I hope my bad english is not making it too hard to understand :c
And of course, thanks for your help whenever you answer this 😄
The text was updated successfully, but these errors were encountered: