Y.Prithvi
Y.Prithvi

Reputation: 1221

Load multiple records into marklogic server

How can I upload multiple records in a file into marklogic server using RESTapi.
I tried to insert simple json format file

[{"Id":100000,"Name":"Dennis"},
{"Id":100001,"Name":"Andrea"},
{"Id":100002,"Name":"Robert"},
{"Id":100003,"Name":"Sara"}]

But, it gives me like one single record.
How do I convert this into 4 different records?

Thanks in advance, Y.Prithvi

Upvotes: 2

Views: 86

Answers (2)

ehennum
ehennum

Reputation: 7335

As Dave points out, the easiest approach is to split out the documents on the client and send a multipart/mixed payload.

The alternative is to write a resource service extension to do the split. In MarkLogic 7, the service must be implemented in XQuery. In MarkLogic 8, you will also be able to implement a service in JavaScript.

The Java API bundles an example that illustrates the basic idea of a service that splits documents:

scripts/docsplit.xqy
com.marklogic.client.example.extension.DocumentSplitter

Upvotes: 2

Dave Cassel
Dave Cassel

Reputation: 8422

There isn't an out-of-the-box way to do that split at the moment. Your best bet is to do a client-side split and then do a bulk-write POST with multiple JSON items to /v1/documents

For the client-side split, you might use something like underscore_cli to do the splitting.

Upvotes: 2

Related Questions