From bf30dbd6dfa1a0b4258617b7c9f44b0df1783dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20de=20CHAVIGNY?= Date: Tue, 6 Feb 2024 16:01:21 -0400 Subject: [PATCH] Update collection.js Solve Error : TypeError: Cannot read properties of undefined (reading 'split') --- lib/collection.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/collection.js b/lib/collection.js index 599a944..d8fe13f 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -14,11 +14,17 @@ class CollectionService extends Service { // Helper function to process stats object processObjectInfos (infos) { // In Mongo the collection name key is ns and prefixed by the db name, change to the more intuitive name just as in create - const namespace = infos.ns.split('.'); - if (namespace.length > 1) { - infos.name = namespace[1]; + if (Object(infos).hasOwnProperty('ns')) { + const namespace = infos.ns?.split('.'); + if (namespace?.length > 1) { + infos.name = namespace[1]; + } + delete infos.ns; } - delete infos.ns; + if (infos.s.namespace.collection) { + infos.name = infos.s.namespace.collection + } + return infos; }