My application has couchbase views (map-reduce). Presently, I am writing them on a text file and loading them for each new couchbase server from the couchbase admin page (tedious and error-prone process).
Is there anyway I can load all those views from text files into couchbase when am deploying a fresh couchbase server or when I create a fresh bucket ?
I remember in mysql, we used to write all insert queries and procedures onto a file and feed the file to mysql (via command prompt) for each new instance. Is there any such strategy available for couchbase ?
From your previous couchbase related questions, it seems you are using the java SDK?
Both 1.4 and 2.0 lines of the SDK allow for programmatically creating desing documents and views.
With Java SDK 1.4.x
You have to load your view definitions (map functions, reduce functions, in which design document to put them) somehow, as Strings. See the documentation at http://docs.couchbase.com/couchbase-sdk-java-1.4/#design-documents.
Basically you create a ViewDesignin a DesignDocument that you insert in the database via the CouchbaseClient:
DesignDocument designDoc = new DesignDocument("beers");
designDoc.setView(new ViewDesign("by_name", "function (doc, meta) {" +
" if (doc.type == \"beer\" && doc.name) {" +
" emit(doc.name, null);" +
" }" +
"}"));
client.createDesignDoc(designDoc);
With Java SDK 2.0.x
In the same way, you have to load your view definitions (map functions, reduce functions, in which design document to put them) somehow, as Strings.
Then you deal with DesignDocument, adding DefaultView to it, and insert the design document in the bucket via Bucket's BucketManager:
List<View> viewsForCurrentDesignDocument = new ArrayList<View>(viewCountForCurrentDesignDoc);
//... for each view definition you loaded
View v = DefaultView.create(viewName, viewMapFunction, viewReduceFunction);
viewsForCurrentDesignDocument.add(v);
//... then create the designDocument proper
DesignDocument designDocument = DesignDocument.create(designDocName, viewsForCurrentDesignDocument);
//optionally you can insert it as a development design doc, retrieve an existing one and update, etc...
targetBucket.bucketManager().insertDesignDocument(designDocument);
At Rounds, we use couchbase for some of our server side apps and use docker images for development environment.
I wrote 2 scripts for dumping an existing couchbase and re-creating couchbase buckets and views from the dumped data.
The view map and reduce functions are dumped as plain javascript files in a directory hierarchy that represents the design docs and buckets in couchbase. It is very helpful to commit the whole directory tree into your repo so you can track changes made to your views.
As the files are plain javascript, you can edit them with your favourite IDE and enjoy automatic syntax checks.
You can use the scripts from the following github repo:
https://github.com/rounds/couchbase-dump
Dump all your couchbase buckets and views as javascript files in a directory hierarchy that you can commit to your repo. Then you can recreate the couchbase buckets and views from previously dumped data.
If you find this helpful and have something to add please create an issue or contribute on github.
Related
I want to synchronize data from a nosql database, have it emit json, and when there is a change and the app is online, have the app pull the changes and update them.
My react-native app uses a few language-specific json files loading them dynamically into javascript objects and then using them as my "database". One file for rendering content, one for the app texts, and one for the styles.
When the user changes the language a different directory is used with the same set of json filenames. This is done via the index.js in that directory and loaded into redux.
Must I change the way my app works, and use a NoSQL/real database directly in the app? So that I can use a solution like this one: synchronizing pouchDB with json data
(that solution is for working if I understand correctly in the exact opposite direction. The app is working with a database and synchronizing with json received from the web)
Or can I update the data in an external (preferably) NoSQL (pouchDB or couchDB) or relational database, and somehow "synchronize" it with the json files, when the app is connected to the web and have it update?
Is there a known method or framework to accomplish this with react-native?
There is a custom implementation in dhtmlx gantt for upload from MPP/XML which goes to their servlet and renders the gantt. Has anyone tried to build a custom CSV upload or any third parties available to load the csv into the gantt.
https://dhtmlx.com/blog/export-import-ms-project-dhtmlx-gantt-chart/
There is no such solution from DHTMLX (FYI I work for DHTMLX), and I'm not aware if there is any third-party service or ready-to-use solution that could be used for a development.
At the code level, importing csv into gantt breaks down into three steps:
parsing CSV into an object array
mapping columns of CSV to properties of that objects (mandatory properties of gantt tasks - text/start_date/duration/parent)
and inserting the result into database.
The first step is trivial. Mapping columns may require implementing some sort of UI so the user could specify which columns of csv mean what in gantt.
For an inspiration, you can check how it's done in this app https://app.ganttpro.com/ - requires registration, but you can create a free account using google or facebook acc - create new project ("+ CREATE NEW" in lefthand menu), select "Import from" and try uploading some csv file -> here is how the ui looks like.
As for the last step - inserting parsed records into db - you'll need to do some coding in order to insert tasks without losing project hierarchy (task.parent -> task.id relations, given that database ids of your items will likely change after inserting), but overall it shouldn't be very difficult.
If you looking for something more specific - please update your question.
I am new to JSON and online databases. I have learned the basics of using .js files and manipulation on them. But I have no clue how to save them onto GAE or Firebase databases.
1)My question is, are every online databases uses JSON differently when they store them?
I have no idea what it looks like storing onto an online database so
2)Can you give me an example of JSON stored in Firebase or GAE. Links to tutorials are also helpful.
Firebase is a true "online database" in a sense that you can save/retrieve/query data to it, without actually writing any code on the server. As such, it is close to Backend as a Service offerings, such as Parse, Kinvey, etc.. Search the web to find more services and compare features that you need.
OTOH, GAE is an application platform - you will need to write server-side code to create any functionality.
As for examples: please RTFM.
GAE's ndb datastore API has a JsonProperty:
https://cloud.google.com/appengine/docs/python/ndb/properties
It's easy to store a JSON object as a StringProperty, using json.loads, json.dumps to parse. For a simple list, you can use a StringProperty, and giving it the repeated=True tag:
https://cloud.google.com/appengine/docs/python/ndb/properties#repeated
I have a number of different types of files stored in a MySQL database (varbinaryMAX). I am in the process of building a document management system and my final phase is to install some sort of document viewer so that these files can be prievewed.
I have veered away from Google Docs due to the security of the documents. I have [preliminarily] settled with Viewer.JS as my chosen method of preview as it supports a wide variety of filetypes, and is free. It does however require a directly accessible URL for the file, which I of course dont have as the file is sitting in a coloumn in the DB.
How would I go about generating a URL that can be used to access a/the file in the DB?
Application is ASP.net
I am trying to build an Employement Management App in AngularJS where a basic operation is adding an employee.
I am displaying details using a service and getting Json data from the mock json file i am using.
Similarly, can i add form data to a textfile on the harddisk.
I have seen it done in a tutorial using $resource.save.
If at all it is possible without any server side code please share the example,it would be helpful.
Thanks.
You can make use of HTML5 local browser storage, as this does not require folder access. Mode datails here http://diveintohtml5.info/storage.html
AngularJS has modules for local storage which you can use to access such storages like this https://github.com/grevory/angular-local-storage