marklogic / node-client-api

The MarkLogic Node.js Client API
https://docs.marklogic.com/jsdoc/index.html
Apache License 2.0
51 stars 45 forks source link

Inserting 2 documents, one temporal and one non-temporal results in both documents being inserted as non-temporal #59

Closed gvaidees closed 9 years ago

gvaidees commented 10 years ago
 before(function(done) {
    this.timeout(3000);
    db.documents.write({
      uri: docuri,
      collections: ['coll0', 'coll1'],
      temporalCollection: 'temporalCollection',
      contentType: 'application/json',
      quality: 10,
      permissions: [
        {'role-name':'app-user', capabilities:['read']},
        {'role-name':'app-builder', capabilities:['read', 'update']}
      ],
      properties: {prop1:'foo', prop2:25},
      content: {
        'System': {
          'systemStartTime' : "",
          'systemEndTime' : "",
        },
        'Valid': {
          'validStartTime': "2001-01-01T00:00:00",
          'validEndTime': "2011-12-31T23:59:59"
        },
        'Address': "999 Skyway Park",
        'uri': "javaSingleDoc1.json",
        id: 12, 
        name: 'Jason'
      }
    },  
    {
      uri: docuri2,
      collections: ['coll0', 'coll1'],
      contentType: 'application/json',
      quality: 10,
      permissions: [
        {'role-name':'app-user', capabilities:['read']},
        {'role-name':'app-builder', capabilities:['read', 'update']}
      ],
      properties: {prop1:'bar', prop2:33},
      content: {id:245, name:'Paul'}
    }
    ).result(function(response){done();}, done);
  });

  it('should read the document content name', function(done) {
    db.documents.read({uris: docuri}).result(function(documents) {
      var document = documents[0];
      document.content.Address.should.equal('999 Skyway Park');
      done();
    }, done);
  });

Code above inserts 2 documents, one temporal and one non-temporal results in both documents being inserted as non-temporal. I see that both documents are ingested as non-temporal. I see the same issue when I insert 2 documents and pass in temporalCollection property for each one of them

ehennum commented 10 years ago

You cannot write a mix of bitemporal and non-bitemporal documents.

In fact, to write bitemporal documents, you must specify the temporalCollection as a peer parameter of the documents parameter because it applies to every document. You do not specify temporalCollection as a peer of the collections parameters, which can be different for different documents. In other words, temporalCollection is similar to the txid parameter and not similar to the permissions parameter.

gvaidees commented 10 years ago

Oh ok. I patterned it after bulk write of non-temporal documents that seem to support different collections for different documents in the bulk payload, such as -

db.documents.write({
      uri: docuri,
      collections: ['coll0', 'coll1'],
      contentType: 'application/json',
      quality: 10,
      permissions: [
        {'role-name':'app-user', capabilities:['read']},
        {'role-name':'app-builder', capabilities:['read', 'update']}
      ],
      properties: {prop1:'foo', prop2:25},
      content: {id:12, name:'Jason'}
    }, {
      uri: docuri2,
      collections: ['coll0', 'coll1'],
      contentType: 'application/json',
      quality: 10,
      permissions: [
        {'role-name':'app-user', capabilities:['read']},
        {'role-name':'app-builder', capabilities:['read', 'update']}
      ],
      properties: {prop1:'bar', prop2:33},
      content: {id:245, name:'Paul'}
    })

I see that bulk write with following payload worked.

    {
      documents: [
      {
        uri: docuri,
        collections: ['coll0', 'coll1'],
        contentType: 'application/json',
        quality: 10,
        permissions: [
          {'role-name':'app-user', capabilities:['read']},
          {'role-name':'app-builder', capabilities:['read', 'update']}
        ],
        properties: {prop1:'foo', prop2:25},
        content: {
          'System': {
            'systemStartTime' : "",
            'systemEndTime' : "",
          },
          'Valid': {
            'validStartTime': "2001-01-01T00:00:00",
            'validEndTime': "2011-12-31T23:59:59"
          },
          'Address': "999 Skyway Park",
          'uri': "javaSingleDoc1.json",
          id: 12, 
          name: 'Jason'
        }
      },
      {
        uri: docuri2,
        collections: ['coll0', 'coll1'],
        contentType: 'application/json',
        quality: 10,
        permissions: [
          {'role-name':'app-user', capabilities:['read']},
          {'role-name':'app-builder', capabilities:['read', 'update']}
        ],
        properties: {prop1:'foo', prop2:50},
        content: {
          'System': {
            'systemStartTime' : "",
            'systemEndTime' : "",
          },
          'Valid': {
            'validStartTime': "2001-01-01T00:00:00",
            'validEndTime': "2011-12-31T23:59:59"
          },
          'Address': "888 Skyway Park",
          'uri': "javaSingleDoc2.json",
          id: 12, 
          name: 'Bourne'
        }
      }
    ], temporalCollection: 'temporalCollection'}
ehennum commented 10 years ago

Yes, that's the expected approach. See the functional specification for more.

ehennum commented 9 years ago

closing because shipped