-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add example for nested schemas using feathers #221
Comments
If you have two separate services you might want to look into doing exactly what the Mongoose "Saving refs" documentation suggests and make to service calls. app.service('authors').create({
name: 'Ian Fleming',
age: 50
}).then(author => {
return app.service('stories').create({
title: 'Casino Royale',
author: author._id // assign the _id from the person
});
}) |
Thank you, but where do I get the dynamic data?
I'm using this boilerplate and I liked that with just the configuration of the database I started to use the REST api for the contacts.. https://github.com/brandiqa/redux-crud-example But now I'm a little lost on where to get access to the data that arrives to the server. If you can guide me a little or at least tell me what topic to read on feather (I've looked at services https://docs.feathersjs.com/api/services.html and database common (https://docs.feathersjs.com/api/databases/common.html) Maybe it's something really simple and when I see it I'll say: hooo, that is... 😄 |
If you really want to submit nested data, this would also work analogous to the Mongoose example by pre-creating an object id and using that to create the nested entries (plus making sure that those data does not get added to the original service call) in a const lodash = require('lodash');
const mongoose = require('mongoose');
app.service('authors').hooks({
before: {
async create(hook) {
const _id = new mongoose.Types.ObjectId();
const { stories } = hook.data;
hook.data._id = _id;
for(let story of stories) {
const storyData = Object.assign({
authorId: _id
}, story);
await hook.app.service('stories').create(story);
}
return hook;
}
}
}); |
Hooo, I see, thank you very much. |
It worked ! I'm starting to getting love with feathers. |
@daffl What a friend, how could I adapt two mongo connections one for the one service in specific and the other for the others service ?? |
For nested schemas where you want to persist them in separate collections ( https://docs.mongodb.com/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/ ) it would be nice to have an example of how to integrate the mongoose way with feathers.js ( section saving-ref )
After a couple of hours I'm still not able to save my nested schema into a separate collection (I'm not sure exactly where to add the example of the saving ref from mongoose url
The text was updated successfully, but these errors were encountered: