Groovy Couchbase help needed - groovy

I am beginner in Groovy and Couchbase. Used Groovy-console to script some basic Groovy. Used couchbase console tool with UI to meddle with documents on couchbase. Now I wanna combine them. I want to meddle with documents in couchbase using Groovy script.
Where can I find an apt tutorial? Or an example code of Groovy-couchbase connection and operation will also help a lot.
(I couldn't find on Google searches, so had to turn to my fellow experts on stackoverflow)
Thank you so much! :-)

All you need is the Java client.
#Grab('com.couchbase.client:java-client:2.2.6')
import com.couchbase.client.java.CouchbaseCluster
// Connect to localhost
def cluster = CouchbaseCluster.create()
// Open the default bucket and the "beer-sample" one
def defaultBucket = cluster.openBucket()
def beerSampleBucket = cluster.openBucket("beer-sample")
// Disconnect and clear all allocated resources
cluster.disconnect()
The Java client documentation is here: http://developer.couchbase.com/documentation/server/4.0/sdks/java-2.2/java-intro.html

Related

How can I use the Python client library for influxdb to for queries? (InfluxDB OSS v1.8.10)

I learned how to download the client library and write to influxdb databases in influxdb OSS v1.8 at this link:
https://docs.influxdata.com/influxdb/v1.8/tools/api_client_libraries/#install-and-use-the-python-client-library
but I can't find out how to use it for querying. My concern is that this version of influx doesn't seem to use buckets, and the explanation on github:
https://github.com/influxdata/influxdb-client-python
only explains how to write and query with buckets. It includes the code that makes querying with v1.8 possible, but it doesn't explain how to use it. If anyone has any tips or resources that could help, please let me know!
The Python Client libraries were developed using the InfluxDB Cloud and InfluxDB 2.0 APIs. Some of these APIs were backported to InfluxDB 1.8, but as you have seen, there are a few differences.
With InfluxDB 1.8, there are two key things to keep in mind:
The "bucket" parameter is the database you wish to read from. For querying, all you need to do is specify the database name. When writing data, it can also take the retention policy via a string like database/retention_policy (e.g. testing/autogen).
To query, your database will need Flux support enabled, which is disabled by default. See this option to enable it. If you are new to Flux, check out this basics page on how to build queries.
Below is a brief example of using the python client library to write a point and then query it back using a flux query:
from influxdb_client import InfluxDBClient, Point
username = ''
password = ''
database = 'testing'
with InfluxDBClient(url='http://localhost:8086', token=f'{username}:{password}', org='-') as client:
with client.write_api() as writer:
point = Point("mem").tag("host", "host1").field("used_percent", 25.43234543)
writer.write(bucket=database, record=point)
querier = client.query_api()
tables = querier.query(f'from(bucket: \"{database}\") |> range(start: -1h)')
for record in tables[0].records:
print(f'{record.get_measurement()} {record.get_field()}={record.get_value()} {record.get_time()}')
Hope that helps!

node and express - how to use fake data

It's been a while since I used node and express and I was sure that this was possible, but i'm having an issue of figuring it out now.
I have a simple postgres database with sequelize. I am building a back end and don't have a populated database yet. I want to be able to provide fake data to use to build the front end and to test with. Is there a way to populate a database when the node server is started? Maybe by reading a json file into the database?
I know that I could point to this fake data using a setting in the environment file, but I don't see how to read in the data on startup. Is there a way to create a local database, read in the data, and point to that?
You can use fake factory package, I think it can solve your problem.
https://www.npmjs.com/package/faker-factory
FakerJs provides that solution.
import { faker } from '#faker-js/faker';
const randomName = faker.name.findName();
const randomEmail = faker.internet.email();
with the above, you can run a loop for loop to be specific to create
the desired data you may need for your project.
Also, check on the free web-API that provides fake or real data to workon

Moving specific collections from mongodb atlas to archive db

I did my homework before posting this question
So the case is that I want to create a utility in my nodejs application that will move specific collections from my main database to an archive database and vice versa. I am using mongo db atlas for my application. I have been doing my research and I found two possible ways one is to create a mongodump and store and other is to create a backup file myself using my node application and upload it to archive db. Using the later approach will cause to loose my collection indexes.
I am planning to use mongodump for the purpose but can't find a resource that shows how to achieve that. Any help would be appreciated. Also if any one has any experience with similar situation I am open to suggestions as well.
I recently created a mongodump & mongorestore wrapper for nodejs: node-mongotools
What does it mean?
you have to install mongo binary on your host by following official mongo documentation(example) and then, you could use node-mongotools to call them from nodeJS.
Here is an example but tool doc contains more details:
var mt = new MongoTools();
const dumpResult = await mt.mongodump({ uri, path })
.catch(console.log);

SBT SDK Blogs and Activities API error

I setup the Social Business Toolkit against our development system. All APIs are working correct, except for the Blog and Activities API.
For both i recieve within the Java APIs the following error:
org.apache.http.conn.EofSensorInputStream cannot be cast to org.w3c.dom.Document
The blog request url from the sbt is:
http://example.com/service/proxy/connections/blogs/homepage/feed/blogs/atom?ps=5&dojo.preventCache=13
But correct would be:
http://example.com/service/proxy/connections/blogs/atom?ps=5&dojo.preventCache=13
Any idea why that happens?
The blog path is customizable per each IBM Connection installation: to support different blogs homepages, there is a parameter exposed on the BlogService API.
To change the default, try:
BlogService svc = ...
svc.defaultHomepageHandle = "";
Lorenzo's answer is correct, most installations use homepage as the blog handle, but you can configure it using the defaultHomepageHandle member variable in the BlogService.
Just a brief comment, maybe it's better to use the setHomepageHandle() method instead.

Problems consuming web service from groovy script

I'm having some problems trying to consume a web service from a groovy script. I'm using WSClient lib.
If I execute the example posted at groovy's website:
#Grab(group='org.codehaus.groovy.modules', module='groovyws', version='0.5.2')
import groovyx.net.ws.WSClient
proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader)
proxy.initialize()
result = proxy.CelsiusToFahrenheit(0)
println "You are probably freezing at ${result} degrees Farhenheit"
Works fine, but once I try to consume another service it crashes with this error:
INFO: Created classes: javac: no
source files Usage: javac
use -help for a list
of possible options 07-jul-2010
9:55:57
org.apache.cxf.endpoint.dynamic.DynamicClientFactory
createC lient GRAVE: Could not compile
java files for http://xxx:8080/x/services/xxx?wsdl.
Caught:
groovyx.net.ws.exceptions.InvokeException:
java.lang.NullPointerExceptio n
at groovy-ws.run(groovy-ws.groovy:13)
The code it's exactly the same (apart from wsdl url which correponds to one internal server). The main difference I found between them is that the second wsdl is RPC style while the first one isn't. I've read that there's some problems to consume RPC like webservices from groovy with WSClient lib. ¿Does anyone know how to consume RPC like webservices with WSClient? ¿Could anyone enlighten me please?
Thank you very much
There seems to be a bug in GroovyWS, documented here on their JIRA.
It's currently Unresolved and was added in 2010.
I'm personally getting the same error with anything other than the trivial example service, with Groovy 1.8.0, GroovyWS 0.5.2
Hopefully somebody can find the issue and fix it - WSClient could definitely be a great alternative to traditional CXF/JAXB
Don't use WSClient is the best answer I can give you. For anything but simple services I've found WSClient does not work well. Instead use what ever java based web service client your most comfortable with and call it from Groovy.

Resources