How to bring the data and document in MarkLogic

Visualizing data - abstract purple background with motion blur, digital data analysis concept
Reading Time: 4 minutes

MarkLogic brings all the features you need into one unified system as it is the only Enterprise NoSQL database. MarkLogic can bring multiple heterogeneous data sources into a single platform architecture, allowing for homogenous data access. For bringing the data we need to insert the documents. On the query console, we are able to perform the query according to requirements.

Bringing in the documents

There are many ways to insert documents into a MarkLogic database. Available interfaces include:

  • MarkLogic Data Hub
  • MarkLogic Content Pump
  • Apache Nifi
  • REST API
  • XQuery functions
  • MuleSoft
  • Data Movement SDK (Java API)
  • Node.js API
  • JavaScript functions
  • Apache Kafka
  • Content Processing Framework
  • XCC
  • WebDAV

Explanation of available interfaces

  • MarkLogic Data Hub: The MarkLogic Data Hub is open-source software that is used to inject data from different sources or from multiple sources. It is used to import the data as well as harmonize the data.
  • MarkLogic Content Pump: It is a command line tool for bulk loading billions of documents into a MarkLogic database, extracting or copying the content. It helps us to make workflow integration very easy.
  • Apache Nifi: It is useful when someone needs to ingest data from a relational database into a MarkLogic Database.
  • REST API: It provides a programming language agnostic way to write a document in MarkLogic.
  • XQuery functions: When we want to write the document to a MarkLogic database then this function is used. Able to write the records from the query console or from the XQuery application.
  • MuleSoft: The Marklogic connector for MuleSoft is Used to bring data from various other systems into the MarkLogic database.

Available Interfaces

  • Data Movement SDK (Java API): Included in the java API, the data movement SDK provides the classes for java developers to use to import and transform documents.
  • Node.js API: It provides Node.js classes for the developers to use to write the document to a MarkLogic database from their Node.js code.
  • JavaScript functions: Able to write the document through the query console or by using the javascript application.
  • Apache Kafka: When we need to stream the data into the database, we can do it by using the Kafka MarkLogic connector.
  • Content Processing Framework: A Pipeline framework for making changes to documents as they are being loaded into the database, such as enriching the data or transforming the PDF or MS office document in XML.
  • XML Contentbase Connector (XCC): If you need to create a multi-tier application that communicates with the MarkLogic then it is useful.
  • WebDAV:  Web Distributed Authoring and Versioning used to drag and drop the documents in the Marklogic Database.

Inserting the document using the Query Console

To insert the document using the query console javaScript or XQuery used. The xdmp.documentLoad() function. Used to load the document from the file system into a database.

declareupdate();

xdmp.documentLoad("path of the source file")

Running a JavaScript expression that makes changes to a database. Need to use the declareUpdate function.

The xdmp.documentinsert() function is used to write a document into a database.

declareUpdate();

xdmp.documentInsert('/employee1.json',

{

'title : 'Knoldus' ,

'description': 'Amazing place to work'

});

Uniform Resource Identifier (URI)

To address any document in a MarkLogic database, it is necessary that each document has a unique URI.

/products/1.json

The URI does not refer to the physical location of a document in a database. Provides a unique name for referencing the document.

Deleting the documents

  • The clear button in the admin interface can be used to delete all the documents in a database.
  • To delete an individual document, the xdmp.documentDelete() function can be used.

declareUpdate();

xdmp.documentDelete('/employee1.json');

Accessing a Document

To read a document in a database, use the cts.doc().

cts.doc('/employee1.json);

Modifying Documents

Documents can be modified via various APIS and tools, including data hub, JavaScript, XQuery, etc.

JavaScript functions for updating documents include:

xdmp.nodeReplace()

xdmp.nodeInsert()

xdmp.nodeInsertBefore()

xdmp.nodeInsertAfter()

xdmp.nodeDelete()

Conclusion

MarkLogic is a NoSql database with many facilities and if someone wants to insert the data then this blog is helpful. After insertion needs to access and modify the document by using some predefined functions.

Reference:

Written by 

Pratibha Yadav is a Software consultant at Knoldus and started her beautiful journey of a career in an environment where she able to sharp - up her skills day by day by learning and earning new opportunities. She completed her Post-graduation from Sharda University, Greater Noida. She is passionate about her work and has knowledge of various programming languages. She is recognized as a quick learner, problem solver, public speaker, dedicated and responsible professional employee. Her hobbies are Writing, Reading, and spending some time with nature.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading