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
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:
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: