-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Docs: boost MongoDB README and tutorial files #4059
Docs: boost MongoDB README and tutorial files #4059
Comments
@agnes512, could you please take a look? Thanks. |
@totolef MongoDB uses
Unfortunately I don't think the controller( REST APIs) work well with inclusion when using MondoDB :( For example, I have a
when create an
the I guess that's why it couldn't find the correct instances if we create the orders with controllers. With MongoDB, the inclusion only works at the repository level. e.g:
|
closing as it's the issue described in #3456. Feel free to continue the discussion over there. |
To make relations work with MongoDB, the foreign key property must be defined as follows: @property({
type: 'string',
mongodb: {dataType: 'ObjectID'},
})
customerId: string This will tell our MongoDB connector to convert string values supplied via REST API to ObjectID values used by the database. I am re-opening this issue, we should improve our documentation to make it more clear what's needed to make relations & inclusion resolvers work with MongoDB. |
I did, my
and
and I even tried this in the
But in MongoDB it still shows that the |
when traverse related models with debugger, the |
@agnes512 thank you for verifying. Looks like my understanding of Could you please share the app you are using to test this? I would like to see if I can spot any easy fix. |
@bajtos sure, thanks! sorry I couldn't figure it out myself 😅 The app: https://github.com/agnes512/lb4Mongo/tree/master/mon And I use I mainly use tests in has-many-inclusion-resolver file to create insatnces: comment out
and These should be able to create instances in the same database |
Here are my findings:
Request body for {
"desc": "a pencil",
"customerId": "5dd6acd8242760334f6aef63"
} Error printed to the console:
The value I am using MongoDB server version 3.4.10. /cc @hacksparrow |
I managed to track down the problem, will open a pull request. |
@bajtos I got the same error too yesterday when I was testing out |
With my fix in place (see loopbackio/loopback-connector-mongodb#553), the records in the database are created with the correct type.
Now I need to verify that inclusion resolvers work too, unfortunately I have run out of time today. |
Weird. When creating new orders via |
I'm unable to get relations to work with MongoDB as well, is there any workaround to get it running at the moment? This is my repository following the Todo and TodoList tutorial |
I'm not seeing todo-list-controller.ts in your project. Perhaps taking another look at the tutorial or compare your code to the prebuilt example might be a good next step. To create the example locally use |
Sorry, missed to push that part of the code, I've updated the repo but still have the issue. Could you tell me how to fix it? |
@SidharthRaveendran Hi, what kind of errors are you getting? Are they related to |
Hi, @agnes512 I'm new to loopback framework, so I'm not sure if it's related to ObjectId or not, but I'm guessing it's related to the inclusion resolver. This is the error i get.
|
@SidharthRaveendran I've just created https://github.com/dougal83/loopback4-example-todo-list-mongodb so you have a reference to work toward. Unfortunately as discussed in this issue the include functionality doesn't appear to be working. |
@dougal83 the include functionality seems to be working in your example! thank you |
@dougal83 But I still can't seem to figure out what part of your code fixed this issue :( |
@SidharthRaveendran I bumped the version of loopback-connector-mongodb to 5.x.x. I suspect that could be the reason, but oddly enough when I run my example the inclusion doesn't work. Probably best to wait for @bajtos who understands the issue. |
I am afraid I don't have bandwidth to look into this issue anytime soon 😢 |
I just checked thoroughly:
These should be documented in mongo connector README and LB3 & LB4 mongodb connector tutorials. |
Steps to reproduce
I just follow the steps described in the following article : Inclusion of related models .
The only changed I made was to use mongodb instead of mySQL, and when I do
I don't get the same result as in the article.
Current Behavior
I currently get :
[ { id: 1, name: 'Thor', }, { id: 2, name: 'Captain', }, ];
Expected Behavior
In the article :
[ { id: 1, name: 'Thor', orders: [ {id: 1, desc: 'Mjolnir', customerId: 1}, {id: 3, desc: 'Rocket Raccoon', customerId: 1}, ], }, { id: 2, name: 'Captain', orders: [{id: 2, desc: 'Shield', customerId: 2}], }, ];
Additional information
The article say :
But in the issue, they speak about the type of the id, and actually, the id returned by Mongodb is a string.
I'm not an expert at all, so I might be missing something.
Would be interested if you have a workaround.
Acceptance Criteria
The text was updated successfully, but these errors were encountered: