Setting collection name dynamically based on original directory structure
up vote
1
down vote
favorite
I would like to dyamically add original directory name as
collection when loading files.
Suppose having following file: /home/sampledata/dir1/targetfile.xml
I would like targetfile.xml included in following collections:
"home", "sampledata", "dir1"
Can we do this while importing via MLCP?
or will be appreciate if anyone can share alternative way to achieve by script.
marklogic
add a comment |
up vote
1
down vote
favorite
I would like to dyamically add original directory name as
collection when loading files.
Suppose having following file: /home/sampledata/dir1/targetfile.xml
I would like targetfile.xml included in following collections:
"home", "sampledata", "dir1"
Can we do this while importing via MLCP?
or will be appreciate if anyone can share alternative way to achieve by script.
marklogic
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to dyamically add original directory name as
collection when loading files.
Suppose having following file: /home/sampledata/dir1/targetfile.xml
I would like targetfile.xml included in following collections:
"home", "sampledata", "dir1"
Can we do this while importing via MLCP?
or will be appreciate if anyone can share alternative way to achieve by script.
marklogic
I would like to dyamically add original directory name as
collection when loading files.
Suppose having following file: /home/sampledata/dir1/targetfile.xml
I would like targetfile.xml included in following collections:
"home", "sampledata", "dir1"
Can we do this while importing via MLCP?
or will be appreciate if anyone can share alternative way to achieve by script.
marklogic
marklogic
asked Nov 8 at 3:23
Njbs
905
905
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You can use this query:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
add a comment |
up vote
1
down vote
I'd recommend using an MLCP transform. It is most often used to manipulate the content before insert, but you can also adjust uri, collections, and more with it.
For generic details on MLCP transform, see: https://docs.marklogic.com/guide/mlcp/import#id_82518
For more specific details on transform output options, see: https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can use this query:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
add a comment |
up vote
1
down vote
accepted
You can use this query:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can use this query:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))
You can use this query:
let $dir-seprator := "/"
for $uri in cts:uri-match("*")[fn:ends-with(.,'.xml')][1 to 10]
let $collection := fn:substring-before($uri,fn:tokenize($uri,$dir-seprator)[fn:last()])
return
xdmp:document-set-collections($uri,fn:tokenize($collection,$dir-seprator)[.!='']))
answered Nov 12 at 12:22
Navin Rawat
2,75111427
2,75111427
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
add a comment |
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
This works, but doesn't scale well. Good for small scale (50k docs max) ad hoc adjustments, but less useful in production..
– grtjn
Nov 13 at 8:16
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
If someone has bigger data size, can enhance this code to run this in batches.
– Navin Rawat
Nov 13 at 9:31
add a comment |
up vote
1
down vote
I'd recommend using an MLCP transform. It is most often used to manipulate the content before insert, but you can also adjust uri, collections, and more with it.
For generic details on MLCP transform, see: https://docs.marklogic.com/guide/mlcp/import#id_82518
For more specific details on transform output options, see: https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
add a comment |
up vote
1
down vote
I'd recommend using an MLCP transform. It is most often used to manipulate the content before insert, but you can also adjust uri, collections, and more with it.
For generic details on MLCP transform, see: https://docs.marklogic.com/guide/mlcp/import#id_82518
For more specific details on transform output options, see: https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
add a comment |
up vote
1
down vote
up vote
1
down vote
I'd recommend using an MLCP transform. It is most often used to manipulate the content before insert, but you can also adjust uri, collections, and more with it.
For generic details on MLCP transform, see: https://docs.marklogic.com/guide/mlcp/import#id_82518
For more specific details on transform output options, see: https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
I'd recommend using an MLCP transform. It is most often used to manipulate the content before insert, but you can also adjust uri, collections, and more with it.
For generic details on MLCP transform, see: https://docs.marklogic.com/guide/mlcp/import#id_82518
For more specific details on transform output options, see: https://docs.marklogic.com/guide/mlcp/import#id_59764
HTH!
answered Nov 8 at 8:45
grtjn
14.7k11730
14.7k11730
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201106%2fsetting-collection-name-dynamically-based-on-original-directory-structure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown