Unable to sync couchbase view in pouchdb using couchbase sync gateway - couchbase

I am trying to get couchbase view result in pouchdb,but pouchdb unable to sync when i tried this code :
remoteDatabase url is(sync gateway url)=http://localhost:4984/sync_gateway
database.replicate.from(remoteDatabase, {
live: true,
retry: true,
filter: '_view',
view: '_design/dev_Test/_views/Test1'
});
It doesnt replicate anything. I want to replicate view as In couchbase I have documents with 100+ fields but in pouch I want only few fields,for that I have created view in couchbase and trying to replicate in pouchdb.
Thanks in advance

Related

Prestashop webapi reset mysql cache by Web API or call SQL by Presta Web Service API

Hi i have problem with Presta WebService. I'm using prestashop with node (nestJS). I Created a connection with MySql database (Presta DB) with SSH tunelling. It works corectly, i can do any query, and SQL returns "OK statuses". I checked it by ssh client, (queries in temrinal) and data is updated in DB. Problem is when i want to select this data by PrestaWebService, when i pick data presta returns "old" propably cached data. On presta Admin i have ceching "off". After manually reset cache by admin panel button keep presta returns me 'old" data. Anyone know whats going on? :D
I found a problem. I used incorrect table. I queried ps_product but should ps_product_shop.

how can i save data to mockapi serve?

i learn ReactJS, And i have homework task. I need create chat. And i need use mockApi server. I chose Mockoon. Server works fine and i can see my data at React app. But how can i save my data to Api?
this is my axios request:
axios.post(`http://localhost:9000/user/`, { user })
.then(res => {
console.log(res);
})
as i understand {user} should send to api my data.
But if i see at console i can see this:
here what i see at console
my data at config: and not at data: and this only at browser. If i reload page al reseted.
So here question, can i save my data from input to mockapi serve?
This is possible with mockswitch - it supports various connectors example local drive (saves to file system ), github (user defined github account - great if you are doing, mongo etc.
Their docs is available here https://mockswitch.com/docs/#storage

Sync Gateway "Channels" in PouchDB

Is there any support for Couchbase Sync Gateway's "Channels" in Pouch DB?
I'd like to be able to have uses see a subset of the overall data and if they create new data to be able to share whom they share it with.
Is that possible with PouchDB? Or would I have to interact with the server directly or use couchbase lite for mobile devices?
Just a little update: This is now possible, PouchDB (since version V3.4.0) is now compatible with sync gateway.
See tutorial here: http://blog.couchbase.com/first-steps-with-pouchdb--sync-gateway-todomvc-todolite
Here is the solution to make the pouch db client work with Couchbase Sync Gateway over user's channels:
var sync = function () {
var opts = {
live: true,
retry: true,
//-- from here
filter: "sync_gateway/bychannel",
query_params: {
"channels": channels
}
//-- to here
};
database.sync(syncServer, opts);
}
The key here is you just pass the filter & query_params as is, the Sync Gateway anyway has the ability to understand this filter.
PouchDB is modeled after CouchDB, which doesn't have the concept of channels, so there are no plans to implement it in PouchDB.
However, one easy way to solve your problem is to sync PouchDB to a CouchDB, then sync that to Couchbase Sync Gateway. The reason you will need CouchDB as an intermediary is that there are a few issues with direct PouchDB <-> Couchbase Sync Gateway syncing, although hopefully they should be resolved soon (see e.g. this and this).
PouchDB syncing through channels / filtered replication
Here's a concrete example to use channels.
var db = new PouchDB("yep");
db.sync(new PouchDB("http://localhost:4984/beer-sample/"), {
live: true,
retry: true,
filter: "sync_gateway/bychannel",
query_params: {
channels: "channel-1,channel-2,channel-3,bar"
}
})
filter: "sync_gateway/bychannel"
Passes the name of filter to apply to the source documents, currently the only supported filter is "sync_gateway/bychannel", this will replicate documents only from the set of named channels.1
query_params.channels
Instead of passing array we separate them by commas.2
Sync Function Example
And in the Sync Gateway your sync function might look like this (It was my intention to keep the sync function as stupid as possible so at one glance you can understand how we used the channels above in PouchDB):
function sync(doc, oldDoc) {
if (doc.type == "beer") {
channel("channel-1");
} else if (doc.type == "soap") {
channel("channel-2");
} else if (doc.type == "sweets") {
channel("channel-3");
} else if (doc.type == "bar") {
channel(doc.type);
}
}
6 years too late though... But it's better late than never!

Dojo 1.9 JsonRest remote url on a different server

I'm trying to get dojo to show Json data that comes from a remote web service. I need to be clear though - the web server hosting the html/dojo page I access isn't the same server as the one that's running the web service that returns the json data - the web service server just can't serve html pages reliably (don't ask!!).
As a test I move the page into the same web server as the web service and the below works. As soon as I move it back so that the html/dojo is served from Apache (//myhost.nodomain:82 say) and the web service sending the json is "{target:http://myhost.nodomain:8181}", then it stops working.
I've used FFox to look at the network & I see the web service being called ok, the json data is returned too & looks correct (I know it is from the previous test), but the fields are no longer set. I've tried this with DataGrid and the plain page below with the same effects.
Am I tripping up over something obvious???
Thanks
require([
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojox/grid/DataGrid",
"dojo/data/ObjectStore",
"dojo/query",
"dojo/domReady!"
],
function(JsonRest, Memory, Cache, DataGrid, ObjectStore, query) {
var myStore, dataStore, grid;
myStore = JsonRest(
{
target: "http://localhost:8181/ws/job/definition/",
idProperty: "JOB_NAME"
}
);
myStore.query("JOB00001"
).then(function(results) {
var theJobDef = results[0];
dojo.byId("JOB_NAME").innerHTML = theJobDef.JOB_NAME;
dojo.byId("SCHEDULED_DAYS").innerHTML = theJobDef.SCHEDULED_DAYS;
});
}
);
Its true what Frans said about the cross domain restriction but dojo has this link to work around the problem.
require(["dojo/request/iframe"], function(iframe){
iframe("something.xml", {
handleAs: "json"
}).then(function(xmldoc){
// Do something with the XML document
}, function(err){
// Handle the error condition
});
// Progress events are not supported using the iframe provider
});
you can simply use this and the returned data can be inserted into a store and then into the grid.
Are you familiar with the Same Origin Policy:
http://en.wikipedia.org/wiki/Same-origin_policy
Basically it restricts websites to do AJAX requests to other domains than the html page was loaded from. Common solutions to overcome this are CORS and JSON-P. However, remember that these restrictions are made for security reasons.

Sync indexedDB with mysql database

I am about to develop an application where employees go to service repair machines at customer premises. They need to fill up a service card using a tablet or any other mobile device.
In case of no Internet connection, I am thinking about using HTML5 offline storage, mainly IndexedDB to store the service card (web form) data locally, and do a sync at the office where Internet exists. The sync is with a MySQL database.
So the question: is it possible to sync indexedDB with mysql? I have never worked with indexedDB, I am only doing research and saw it is a potential.
Web SQL is deprecated. Otherwise, it could have been the closer solution.
Any other alternatives in case the above is difficult or outside the standard?
Your opinions are highly appreciated.
Thanks.
This is definitly do able. I am only just starting to learn indexeddb the last couple of days. This is how I would see it working tho. Sorry dont have code to give you.
Website knows its in offline mode somehow
Clicking submit form saves the data into indexeddb
Later laptop or whatever is back online or on intranet and can now talk to main server sends all indexeddb rows to server to be stored in mysql via an ajax call.
indexeddb is cleared
repeat
A little bit late, but i hope it helps.
This is posible, am not sure if is the best choice. I can tell you that am building a webapp where I have a mysql database and the app must work offline and keep trace of the data. I try using indexedDB and it was very confusing for me so I implemented DexieJs, a minimalistic and straight forward API to comunicate with indexedDB in an easy way.
Now the app is working online then if it goes down the internet, it works offline until it gets internet back and then upload the data to the mysql database. One of the solutions i read to save the data was to store in a TEXT field the json object been passed to JSON.stringify(), and once you need the data back JSON.parse().
This was my motivation to build the app in that way and also that we couldn't change of database :
IndexedDB Tutorial
Sync IndexedDB with MySQL
Connect node to mysql
[Update for 2021]
For anyone reading this, I can recommend to check out AceBase.
AceBase is a realtime database that enables easy storage and synchronization between browser and server databases. It uses IndexedDB in the browser, and its own binary db format or SQL Server / SQLite storage on the server side. MySQL storage is also on the roadmap. Offline edits are synced upon reconnecting and clients are notified of remote database changes in realtime through a websocket (FAST!).
On top of this, AceBase has a unique feature called "live data proxies" that allow you to have all changes to in-memory objects to be persisted and synced to local and server databases, so you can forget about database coding altogether, and program as if you're only using local objects. No matter if you're online or offline.
The following example shows how to create a local IndexedDB database in the browser, how to connect to a remote database server that syncs with the local database, and how to create a live data proxy that eliminates further database coding altogether.
const { AceBaseClient } = require('acebase-client');
const { AceBase } = require('acebase');
// Create local database with IndexedDB storage:
const cacheDb = AceBase.WithIndexedDB('mydb-local');
// Connect to server database, use local db for offline storage:
const db = new AceBaseClient({ dbname: 'mydb', host: 'db.myproject.com', port: 443, https: true, cache: { db: cacheDb } });
// Wait for remote database to be connected, or ready to use when offline:
db.ready(async () => {
// Create live data proxy for a chat:
const emptyChat = { title: 'New chat', messages: {} };
const proxy = await db.ref('chats/chatid1').proxy(emptyChat); // Use emptyChat if chat node doesn't exist
// Get object reference containing live data:
const chat = proxy.value;
// Update chat's properties to save to local database,
// sync to server AND all other clients monitoring this chat in realtime:
chat.title = `Changing the title`;
chat.messages.push({
from: 'ewout',
sent: new Date(),
text: `Sending a message that is stored in the database and synced automatically was never this easy!` +
`This message might have been sent while we were offline. Who knows!`
});
// To monitor realtime changes to the chat:
chat.onChanged((val, prev, isRemoteChange, context) => {
if (val.title !== prev.title) {
console.log(`Chat title changed to ${val.title} by ${isRemoteChange ? 'us' : 'someone else'}`);
}
});
});
For more examples and documentation, see AceBase realtime database engine at npmjs.com