-
Notifications
You must be signed in to change notification settings - Fork 125
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
nested objects #184
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone who is having problem storing nested object in metadata:
Winston is formatting the object, and adding some extrafield, if you want to store the object as it is
In the winston-mongodb node module, there's a helpers.js file, which contain this function
function cloneMeta(node, opt_parents) { if (!(node instanceof Object) || (node instanceof ObjectID) || (node instanceof Buffer)) { return node; } let copy = Array.isArray(node) ? [] : {}; if (node instanceof Date) { return new Date(node.getTime()); } else if (node instanceof Error) { // This is needed because Error's message, name and stack isn't accessible when cycling through properties copy = {message: node.message, name: node.name, stack: node.stack}; } opt_parents = opt_parents || []; opt_parents.push(node); for (let key in node) { if (!Object.prototype.hasOwnProperty.call(node, key)) { continue; } let value = node[key]; let newKey = key; if (newKey.includes('.') || newKey.includes('$')) { newKey = newKey.replace(/\./g, '[dot]').replace(/\$/g, '[$]'); } if (value instanceof Object) { if (opt_parents.indexOf(value) === -1) { copy[newKey] = cloneMeta(value, opt_parents); } else { copy[newKey] = '[Circular]'; } } else { copy[newKey] = value; } } opt_parents.pop(); return copy; }
Which format meta if type is object, you only have to remove the "not operator" and return the object as it is in return node
The text was updated successfully, but these errors were encountered: