Reputation: 539
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)
Upvotes: 2
Views: 162
Reputation: 539
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.
Upvotes: 1
Reputation: 28351
As TAM said, you could probably do that with UPDATE statement from N1QL
in Couchbase 4.1... but you're using 3.0.
In Couchbase 3.x, your best best is to write:
view
that will allow you to get IDs of all documents of type Foo
Foo
docBar
id from the content of the Foo
docBar
docFoo
content accordingly and save (update) the Foor
document in dbUpvotes: 4
Reputation: 1741
I guess you mean some declarative solution resembling SQL UPDATE. Such a thing isn't available for CB 3, but since CB 4.1, N1QL has an UPDATE statement. Check http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-language-reference/update.html.
Upvotes: 4