-
Notifications
You must be signed in to change notification settings - Fork 198
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
ObjectId from mongodb will not correct by using flatten methods #60
Comments
Had the same problem, so I fixed it in #61 - let me know if it works for you |
It not work for me!
When I use
Suggest: You just need to convert type from ObjectId to String by coding like this:
And I will try again after you fixed this. |
Works fine for me, It's already in production on our application :) You need to: npm install vendigo-group/flat # use my branch until this PR is merged. Then use the following code: const coercion = [{
test: (key, value) => value && value._bsontype === 'ObjectID',
transform: value => { return value.valueOf().toString() }
}]
flatten(yourobject, { coercion: coercion }) There are tests covering the code in the pull request, so feel free to inspect those to help you. The code you have suggested, by the way, has a number of issues:
|
In #64 I've proposed yet another solution using the |
@juanjoDiaz your solution is fine - however its scope is very small - there are precious few objects which are generous enough to provide a Also - as a side note, you left a |
damn! good catch... Yeah. Certainly the scope is small. The idea was to modify just the minimum and cover the most possible cases. As I mention in the PR, 'm happy with any solution that cover this use case :) |
I've decided to fork and republish as https://www.npmjs.com/package/flatley Let me know if you have further issues (ideally provide me with a reproduction) and I'll endeavour to fix them. |
No description provided.
The text was updated successfully, but these errors were encountered: