How to use marklogic - 10 common examples

To help you get started, we’ve selected a few marklogic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / index.js View on Github external
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');

var funcs = {};
var moment = require('moment-timezone');
// funcs.exploreSearch = require('./exploreSearch');
funcs.patch = require('./patch');

funcs.search = function (spec) {
  // TODO: should really be supporting the txid param
  // query function wants an args list so we use apply since we
  // are dynamically creating values out of what is specified
  // console.log(require('util').inspect(this));
  // console.log(JSON.stringify(spec));
  return this.documents.query.apply(
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / index.js View on Github external
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');

var funcs = {};
var moment = require('moment-timezone');
// funcs.exploreSearch = require('./exploreSearch');
funcs.patch = require('./patch');

funcs.search = function (spec) {
  // TODO: should really be supporting the txid param
  // query function wants an args list so we use apply since we
  // are dynamically creating values out of what is specified
  // console.log(require('util').inspect(this));
  // console.log(JSON.stringify(spec));
  return this.documents.query.apply(
    this,
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / old / patchQuestion.js View on Github external
* Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var _ = require('lodash');
var uuid = require('node-uuid');

var db;
var questionsDir = '/questions/';
var contributorPrefix = 'com.marklogic.samplestack.domain.Contributor';
var contributorDir = contributorPrefix + '/';
// TODO: pull contributor info from session
var contributorId = 'cf99542d-f024-4478-a6dc-7e723a51b040';
var contributorDisplayName = 'JoeUser';
var contributorUserName = 'joe@example.com';

var commentTemplate = {
  'owner': {
    'id': contributorId,
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / util.js View on Github external
var Promise = require('bluebird');
var errs = libRequire('errors');
var qb = require('marklogic').queryBuilder;

module.exports = {
  // POJO-managed docs "bury" the content under a Java fully qualified
  // class name, so we find the first key an use it to locate the actual
  // content
  unwrapPojo: function (pojo) {
    return pojo[Object.keys(pojo)[0]];
  },

  getOnlyContent: function (response) {
    if (response.length !== 1) {
      throw errs.cardinality({ length: response.length,
        response: response });
    }
    else {
      return response[0].content;
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / index.js View on Github external
*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');

var funcs = {};

/**
 * Handle an update to a contributor's reputation by patch the document.
 *
 * @param  {String} txid The transaction ID.
 * @param  {String} id The contributor ID.
 * @param  {Number} repChange Increment or decrement value.
 * @return {Promise} A promise object.
 */
funcs.patchReputation = function (txid, id, repChange) {
  // add (or subtract) from reputation property
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / old / getContributor.js View on Github external
* 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var qb = require('marklogic').queryBuilder;

module.exports = function (userSpec) {
  var self = this;

  return new Promise(function (resolve, reject) {
    // TODO: should thie really be approx. 2-times slower? are we missing
    // an index?
    // self.documents.query(
    //   qb.where(
    //     qb.directory('com.marklogic.samplestack.domain.Contributor/'),
    //     qb.value('id', userId)
    //   )
    // ).result(
    //
    var fetch;
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / qnaDoc / old / patchQuestion.js View on Github external
* you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 

var Promise = require('bluebird');
var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var _ = require('lodash');
var uuid = require('node-uuid');

var db;
var questionsDir = '/questions/';
var contributorPrefix = 'com.marklogic.samplestack.domain.Contributor';
var contributorDir = contributorPrefix + '/';
// TODO: pull contributor info from session
var contributorId = 'cf99542d-f024-4478-a6dc-7e723a51b040';
var contributorDisplayName = 'JoeUser';
var contributorUserName = 'joe@example.com';

var commentTemplate = {
  'owner': {
    'id': contributorId,
    'displayName': contributorDisplayName,
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / index.js View on Github external
* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var mlclient = require('marklogic');
var qb = mlclient.queryBuilder;
var pb = mlclient.patchBuilder;
var meta = require('./meta');
var util = libRequire('db-client/util');

var funcs = {};

/**
 * Handle an update to a contributor's reputation by patch the document.
 *
 * @param  {String} txid The transaction ID.
 * @param  {String} id The contributor ID.
 * @param  {Number} repChange Increment or decrement value.
 * @return {Promise} A promise object.
 */
funcs.patchReputation = function (txid, id, repChange) {
  // add (or subtract) from reputation property
  return this.documents.patch({
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / old / getContributor.js View on Github external
//   )
    // ).result(
    //
    var fetch;

    if (userSpec.contributorId) {
      fetch = self.documents.read(
        'com.marklogic.samplestack.domain.Contributor/' +
            userSpec.contributorId +
            '.json'
      );
    }
    else {
      fetch = self.documents.query(
        qb.where(
          qb.directory('com.marklogic.samplestack.domain.Contributor/'),
          qb.value('userName', userSpec.uid)
        )
      );
    }
    fetch.result(
      function (response) {
        if (response.length !== 1) {
          return reject({
            error: 'cardinalityViolation',
            userSpec: userSpec,
            count: response.length
          });
        }
        var obj = response[0].content[
          Object.keys(response[0].content)[0]
        ];
github marklogic-community / marklogic-samplestack / appserver / node-express / lib / db-client / contributor / old / getContributor.js View on Github external
//     qb.value('id', userId)
    //   )
    // ).result(
    //
    var fetch;

    if (userSpec.contributorId) {
      fetch = self.documents.read(
        'com.marklogic.samplestack.domain.Contributor/' +
            userSpec.contributorId +
            '.json'
      );
    }
    else {
      fetch = self.documents.query(
        qb.where(
          qb.directory('com.marklogic.samplestack.domain.Contributor/'),
          qb.value('userName', userSpec.uid)
        )
      );
    }
    fetch.result(
      function (response) {
        if (response.length !== 1) {
          return reject({
            error: 'cardinalityViolation',
            userSpec: userSpec,
            count: response.length
          });
        }
        var obj = response[0].content[
          Object.keys(response[0].content)[0]