Details
-
Improvement
-
Resolution: Won't Fix
-
Major
-
sdk-3.2, sdk-3.3
-
DOC-2022-S4, DOC-2022-S5, DOC-2022-S6, DOC-2022-S7, DOC-2022-S8, DOC-2022-S9
-
1
Description
In the transaction code block below what is “collection”?
For example ctx.insert(collection, “doc-a”, {})
const inventory = cluster.bucket('travel-sample').scope('inventory')try { |
await cluster.transactions().run(async (ctx) => {
|
// Inserting a doc: |
await ctx.insert(collection, 'doc-a', {}) // Getting documents: |
const docA = await ctx.get(collection, 'doc-a') // Replacing a doc: |
const docB = await ctx.get(collection, 'doc-b') |
const content = docB.content |
const newContent = { |
transactions: 'are awesome', |
...content,
|
}
|
await ctx.replace(docB, newContent) // Removing a doc: |
const docC = await ctx.get(collection, 'doc-c') |
await ctx.remove(docC) // Performing a SELECT N1QL query against a scope: |
const qr = await ctx.query('SELECT * FROM hotel WHERE country = $1', { |
scope: inventory,
|
parameters: ['United Kingdom'], |
})
|
// ...qr.rows |
qr.rows await ctx.query('UPDATE route SET airlineid = $1 WHERE airline = $2', { |
scope: inventory,
|
parameters: ['airline_137', 'AF'], |
}) })
|
} catch (error) { |
if (error instanceof TransactionFailedError) { |
console.error('Transaction did not reach commit point', error) |
} if (error instanceof TransactionCommitAmbiguousError) { |
console.error('Transaction possibly committed', error) |
}
|
}
|
|