3

I am trying to insert multiple documents into the MarkLogic database using Rest-API. I wanted to customize the uri while inserting by specifying particular attribute as uri. Here is the json file:

{
    "id" : "101",
    "firstName" : "I",
    "middle name" : "Love",
    "last name : "Myself",
    "emailId" : "aaa@gmail.com" 
}

If I wanted to specify emailId attribute of json mentioned above as uri while inserting the record. Can anybody let me now, How to achieve it?

Sofia
  • 771
  • 1
  • 8
  • 22
RCS
  • 1,370
  • 11
  • 27

1 Answers1

2

Once you've initialized a REST API server instance, you specify document URI using the PUT command:

$ curl --anyauth --user user:password -X PUT -d@'./one.xml' \ -H "Content-type: application/xml" \ 'http://localhost:8000/LATEST/documents?uri=/xml/one.xml'

wst
  • 11,681
  • 1
  • 24
  • 39
  • hi @wst how to get his done for multiple files in a folder? Meaning if I have 10 json files inside a folder and If i just specify the folder name using `-d@'./folderName'`, how to generate the uri's on the fly(dynamically)? – DMA Jun 13 '16 at 15:17
  • 2
    The REST API support POST requests with a multipart/mixed payload for bulk writes. The Content-Disposition header for each document specifies the URI. See http://docs.marklogic.com/guide/rest-dev/bulk#id_54649 and note that the Java Client API and Node.js API provide interfaces that build multipart requests for you. – ehennum Jun 13 '16 at 15:25
  • 2
    @DMA, any REST API is usually accessed programmatically. curl is a program that can access a REST API for very simple use cases. For the use case you're presenting I think you'd use a more capable language, like sh or Java. Or if you're just looking for a simple solution and you don't need to use REST, take a look at mlcp. https://developer.marklogic.com/products/mlcp – Sam Mefford Jun 13 '16 at 15:45
  • I have asked how to specify one of the attribute of json/XML as uri, while inserting multiple document in folder. – RCS Jun 14 '16 at 02:19
  • 2
    @RCS, I believe the answer to your question is you write some code in your favorite programming language which can talk HTTP or REST. Or, if you're just looking for a simple solution and you don't need to use REST, take a look at mlcp. https://developer.marklogic.com/products/mlcp – Sam Mefford Jun 16 '16 at 16:29
  • 1
    Thanks Sam for the reply. I have created one custom transform function and used it with mlcp which does the job for me. – RCS Jun 16 '16 at 17:26