-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (50 loc) · 1.94 KB
/
index.js
File metadata and controls
61 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('dotenv').config(); // add .env variables
var couchbase = require('couchbase'); // setup couchbase SDK
async function main() {
const clusterConnStr = process.env.NODE_COUCHBASE_CONNECTION_STRING;
const username = process.env.NODE_COUCHBASE_USERNAME;
const password = process.env.NODE_COUCHBASE_PASSWORD;
const bucketName = process.env.COUCHBASE_DEFAULT_BUCKET
const cluster = await couchbase.connect(clusterConnStr, {
username: username,
password: password,
// Sets a pre-configured profile called "wanDevelopment" to help avoid latency issues
// when accessing Capella from a different Wide Area Network
// or Availability Zone (e.g. your laptop).
configProfile: 'wanDevelopment',
})
const bucket = cluster.bucket(bucketName)
// Get a reference to the default collection, required only for older Couchbase server versions
const defaultCollection = bucket.defaultCollection()
const collection = bucket.scope('tenant_agent_00').collection('users')
const user = {
type: 'user',
name: 'Michael',
email: 'michael123@test.com',
interests: ['Swimming', 'Rowing'],
}
// Create and store a document
await collection.upsert('michael123', user)
// Load the Document and print it
// Prints Content and Metadata of the stored Document
let getResult = await collection.get('michael123')
console.log('Get Result: ', getResult)
// Perform a SQL++ (N1QL) Query
const queryResult = await bucket
.scope('inventory')
.query('SELECT name FROM `airline` WHERE country=$1 LIMIT 10', {
parameters: ['United States'],
})
console.log('Query Results:')
queryResult.rows.forEach((row) => {
console.log(row)
})
}
// Run the main function
main()
.catch((err) => {
console.log('ERR:', err)
process.exit(1)
})
.then(process.exit)
module.exports = main;