Your code should be as follow.First try with my code then just replace logic to add path.
if (!document.hasAspect("cm:taggable"))
document.addAspect("cm:taggable");
document.addTag("test");
You can replace "test" with accessed path of your document.