Search code examples
couchbasebulkupdatedatabasenosql

Couchbase - Creating new property in all document types Foo where its value is taken from document type Bar?


Foo: {
 id: 100,
 barId: 123, 
 startDate: "12/12/79", //new field to be added 
} ,    

Bar: { 
 id: 123,
 startDate: "12/12/79",
}

We need to create a new property 'startDate' in all document types 'Foo' that its value is taken from document type 'Bar'.

All 'Foo' documents contain a "foreign key" to Bar (a field called 'BarId').

What is the easiest way to do it besides retrieving and updating all entities programmatically ? (Couchbase version is 3.0)


Solution

  • UPDATE didn't quite work for me since I need to perform some sort of a "join" between 2 document types. But it looks like Couchbase's MERGE statement is just what I needed.

    http://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/merge.html

    We'll upgrade to 4.1 and see how it goes.