示例#1
0
DBManager.loadDocuments = function(folder, database, callback) {

    var settings = mlutil.copyProperties(this.settings.connection);
    //Need to connect to Rest API, not management one
    settings.port = this.httpSettings.port;
    settings.database = database;
    var db = marklogic.createDatabaseClient(settings);

    recursive(folder, function (err, files) {
        var callBackwhenDone = (function() { var total = files.length;
            return function() {
                total = total-1;
                if (total < 1) {
                    callback();
                }
            };
        })();

        if (err) {
            logger.error(folder + ' Folder not found');
            process.exit(1);
        }
        files.forEach(function(file){
            var document = fs.readFileSync(file, 'utf8');
            db.documents.write(
              {
                uri: file.replace(new RegExp('^'+folder),''),
                content: document
              }
            ).result(
                function(response) {
                    callBackwhenDone();
                },
                function(error) {
                    logger.error('Error loading file ' + file);
                    logger.error(error);
                    process.exit(1);
                }
            );
        });
    });
};
示例#2
0
var marklogic = require("marklogic");
var conn = require("./env.js").connection

var qb = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(conn);

module.exports = function () {
    
    // MarkLogic
    return {
        // Keyword Search through parsing the input string
        Keysearch : function (request, response) {
            
            try {
                var searchString = "";
                if (request.body.SearchString) {
                    searchString = request.body.SearchString;
                }
                
                db.documents.query(
                    qb.where(
                        qb.collection("housedata"),
                        qb.parsedFrom(searchString))
                            .orderBy(qb.sort('price'))
                                //.slice(qb.snippet())
                                //.withOptions({ categories: ['content', 'metadata'] })
                                //.withOptions({categories: ['content']})
                )
                    .result(function (documents) {
                    if (documents.length > 0) {
                        response.render('index', { search : 'KeyWord' , session : request.session, results : documents, searchString : searchString }); 
// Search for documents that contain the phrase 'iphone 4' -- note the extra
// layer of quotes.

var ml = require('marklogic');
var conn = require('../config.js').admin;
var db = ml.createDatabaseClient(conn);
var qb = ml.queryBuilder;

db.documents.query(
  qb.where(
    qb.term('"iphone 4"')
  )
  .withOptions({metrics: true})
).result()
.then(function(docs) {
  console.log('This search found ' + docs[0].total + ' docs');
})
.catch(function(error) {
  console.log('something went wrong: ' + error);
});
var config = require('./config'),
    marklogic = require('marklogic');

var serviceName = 'testService';

var db = marklogic.createDatabaseClient({
  host: config.host,
  port: config.database.port,
  user: config.auth.user,
  password: config.auth.pass,
  authType: 'digest'
});

// BUG: LIST OF ARGS DOES NOT WORK
//db.resources.remove('testService', {basename: 'three'}, {key: 'value'})
// ARGS AS SINGLE OBJECT WORKS
db.resources.remove({
  name: 'testService',
  params: {basename: 'three'},
  documents: {key: 'value'}
})
  .result(function(response){
    console.log(JSON.stringify(response, null, 2));
  });
var marklogic = require('marklogic'),
    stream = require('stream');

var db = marklogic.createDatabaseClient({
  user: '******',
  password: '******'
});

var json = '{"foo": "bar3"}';

var docDescr3 = {
  uri: '/doc3.json',
  content: json
}

db.documents.write(docDescr3)
  .stream()
  .on("data", function (res) {
    console.log('successful write 3');
    console.dir(res);
  })
  .on("error", function (err) {
    console.log('failed write 3');
    console.error(err)
  });

var writable = new stream.Writable({
  write: function(chunk, encoding, next) {
    console.log(chunk.toString());
    next();
  }
示例#6
0
DBManager.prototype.getDatabaseClient = function () {
    if(!this.dbClient){
        this.dbClient = marklogic.createDatabaseClient(this.settings.connection);
    }
    return this.dbClient;
};
示例#7
0
var config = require('./config'),
    marklogic = require('marklogic');

var db = marklogic.createDatabaseClient({
  host: config.host,
  port: config.port,
  authType: 'kerberos'
});

db.setLogger('debug');

db.documents.read(
  '/file.html'
).result( function(documents) {
  console.log('success');
  console.log(JSON.stringify(documents));
}, function(error) {
    console.log('error');
    console.log(JSON.stringify(error, null, 2));
});
// Read a document from the database.
//
// The hon-reader user has no roles, and so does not have permission to read
// the document.

var ml = require('marklogic');
var nobody = require('../config.js').nobody;
var db = ml.createDatabaseClient(nobody);

// document URI in the database
var imgURI = '/image/01.JPG.json';

db.documents.read(imgURI).result()
  .then(function(docs) {
    // write out the document
    console.log(docs[0]);
  })
  .catch(function(error) {
    console.log('Not happening: ' + '(' + error.statusCode + ') ' + error.message);
  });
// Read a document from the database.
//
// hon-reader has the 'rest-reader' role, which does have permission to read
// the document. Why? Because when a document is inserted through the REST API,
// rest-reader is given 'read' and rest-writer is given 'update'.

var ml = require('marklogic');
var reader = require('../config.js').reader;
var db = ml.createDatabaseClient(reader);

// document URI in the database
var imgURI = '/image/01.JPG.json';

db.documents.read(imgURI).result()
  .then(function(docs) {
    // write out the document
    console.log(docs[0]);
  })
  .catch(function(error) {
    console.log(error);
  });
示例#10
0
'use strict';

const express = require('express');
const app     = express();
const router  = express.Router();
const jwt = require('jsonwebtoken');
const marklogic = require('marklogic');
const settings  = require('./settings');

const db = marklogic.createDatabaseClient(settings.connection);
const qb = marklogic.queryBuilder;

app.set('port', 8080);
app.use('/', router);

const authenticate = (req, res, next) => {
  const authHeader = req.headers.authorization;
  if (authHeader) {
    const token = authHeader.split(' ')[1];
    jwt.verify(token, 's3cr3t', (error, decoded) => {
      if (error) {
        console.log(error);
        res.sendStatus(401);
      } else {
        req.username = decoded.username;
        next();
      }
    });
  } else {
    res.status(403).send({message: 'No token provided.'});
  }
示例#11
0
var marklogic = require("marklogic");
var my = require("./my-connection.js");

// MarkLogic db
var mldb = marklogic.createDatabaseClient(my.connInfo);
var q = marklogic.queryBuilder;

var count = 0;

mldb.documents.query(
	q.where(
		q.collection("ios_reviews")
	)
).result(function(documents) {
	documents.forEach(function(document) {
		mldb.documents.remove(document["uri"]).result(function(response) {
			count++;
			console.log(count);
		});
	});
});

// do MarkLogic queries only return things in batches of 10???