Files
mongo/jstests/libs/namespace_utils.js
Malik Endsley dd38479625 SERVER-114308: Clean up collections pre-created in set_recordids_replicated.js where necessary (#44721)
GitOrigin-RevId: 09c31b57e516faa8ff7e26b5f931287bf3dbf588
2025-12-22 23:31:39 +00:00

30 lines
788 B
JavaScript

/**
* Returns the collection name extracted from a namespace string.
*/
export function getCollectionNameFromFullNamespace(ns) {
return ns.split(/\.(.+)/)[1];
}
/**
* Returns the database and collection name extracted from a namespace string.
*/
export function getDBNameAndCollNameFromFullNamespace(ns) {
return ns.split(/\.(.+)/);
}
/**
* Returns whether the collection name is valid. See NamespaceString::validCollectionName().
*/
export function isValidCollectionName(collName) {
if (typeof collName !== "string" || collName.length === 0) {
return false;
}
if (collName.includes("\0")) {
return false;
}
if (collName === "oplog.$main") {
return true;
}
return !collName.startsWith(".") && !collName.includes("$");
}