Closed Suprit-S-M closed 7 years ago
If you following the Getting Started instructions and the Documentation section you will see that the API is self documented by using the help()
method.
Based on that the code would be:
import Couchbase from "react-native-couchbase-lite";
Couchbase.initRESTClient(manager => {
manager.database.put_db({db: DB_NAME})
.then(res => manager.document.post({db: DB_NAME, body: {city: 'brighton'}}))
.then(res => console.log(`Response object :: ${res.obj}`));
});
I'll close this ticket but let us know if you have any questions regarding this.
Yes , thank you but I am getting status : 400 error : Invalid database/document/revision ID .
Could you please help me to solve this issue . I am new to Couchbase-lite
Database names can't contain certain characters. See https://developer.couchbase.com/documentation/mobile/1.3/guides/couchbase-lite/native-api/database/index.html
Thank you
How to get inserted values from document . Is following code right ..?
manager.document.get({db:DB_NAME}).then(res => { })
You need to specify a document ID as the manager.document.get.help()
method would indicate in the console. So it would be:
manager.document.get({db: 'todos', doc: 'docid'})
.then(res => console.log(res.obj));
You can query all document in the database too. Look for the get_db_all_docs
method with manager.query.help();
.
Thank you , thanks for your time .
How to get the document id , for me manager.document.get.help() is giving error . Lets say for example if I have multiple documents in one bucket , how to get doc it.
Thanks
This is what manager.document.get.help()
prints to the console
It helps you to write the code, not find the document ID. You need to get the document ID from another method (like _all_docs).
See README Documentation and portal documentation for the REST API.
Okay , many thanks ,
Hello jamiltz ,
Thanks for your guidance and your time . All working fine for me .
Now I want to replicate my local DB data into Remote Couchbase DB , how can we do this .
I tried manager.server.post_replicate({}); but it did not worked .
Here's how its done in the sample app https://github.com/couchbaselabs/mobile-training-todo/blob/master/react-native/app/DataManager.js#L94-L97
This should help you get replication up and running.
This I tried but I am not able to get local db document on remote db . The code I followed . Please help me to solve this issue . I am not getting how to push created document from local remote db.
What's the config file you used for Sync Gateway? Are you running the app on Android or iOS?
I am running it on ios and the sync gateway file is
{ "log":[""], "databases":{ "otc2": "http://localhost:8091", "users":{ "GUEST" : {"disabled":false , "admin_channels":[""] } } } }
I have created DB called otc2 on local and remote CB and created document called docid on local DB and inserted some values . These values I want to replicate to remote DB .
Hello could you please help me .
Take a look at the Example section on this page https://github.com/couchbaselabs/couchbase-mobile-portal/blob/master/md-docs/ready/installation/react-native.md. Hopefully that helps.
This I tried but it is not working , is there anything to configure extra..?
There shouldn't be. It worked fine for me this morning with the iOS simulator.
I am getting following error in remote CB , I do verified in Logs
invalid post received: {mochiweb_request, [#Port<>,'POST',"/otc222/_revs_diff", {1,1}, {8, {"host", {'Host',"ipaddress:8091"}, {"content-type", {'Content-Type',"application/json"}, {"connection", {'Connection',"keep-alive"}, {"accept", {'Accept',"application/json"}, nil, {"accept-language", {'Accept-Language',"en-us"}, {"accept-encoding", {'Accept-Encoding',"gzip, deflate"}, nil,nil}, nil}}, {"content-length", {'Content-Length',"326"}, nil,nil}}, nil}, {"user-agent", {'User-Agent', "CouchbaseLite/1.3 (iOS 1.3.1/)"}, nil,nil}}}]}
Hard to say what's going on from this snippet, sorry :(
Thats okay ,
Thank you
will this manager.server.post_replicate () do two-way sync . Means from remote to local and local to remote .
Because couchbase documentation provides push and pull api's . But these will be in different language .
As long as you call the manager.server.post_replicate
method twice swapping around the source and target you will have bi-directional sync. You're right, the native API on the dev portal is a totally different syntax.
Okay , then you meant say following code will be a bi-directional sync
return manager.server.post_replicate({body: {source: SG_URL, target: DB_NAME, continuous: true}}) .then(res => manager.server.post_replicate({body: {source: DB_NAME, target: SG_URL, continuous: true}})) .catch(e => console.log('ERROR', e));
If yes , first call is for local to remote and second one is for remote to local . am I right ..?
Yes, you're right
Okay , but I am confused , In first call we have {body:{source:SG_URL,target:DB_NAME}} this from local to remote .
And I expect following syntax for remote to local
{body:{target:DB_NAME,source:SG_URL}} but this is not the case . Could you please explain me
Yeah , I got it working and thanks for your time . I have one more doubt
How to register for remote DB changes in react native and how to import DeviceEventEmitter
See the code in https://github.com/couchbaselabs/mobile-training-todo/tree/master/react-native. If you want to register for changes on the local db, check out Feed.js.
Yeah that i got it , thanks . But what if I want to register for changes on the remote db . As soon as changes happen to remote DB I want get callback , for that i need to register listener . But I am not getting how to add listener for that .
Is it possible to register change listener for remote DB changes ...?
You can use the swagger client against the public Sync Gateway REST API. For example, in the training app this is done to check the validity of the username/password. You could use the swagger client to subscribe to changes on the server side as well.
Hello ,
I wanted to create database and document in simple step , Means I just wanted syntax to create DB. Could you please provide me sample steps to create it .
1 . Create DB 2 . Create Document 3 . Insert initial values
I wanted something like this , below code is in C#
var database = Manager.SharedInstance.GetDatabase("mydb");
// Create a new document (i.e. a record) in the database. var document = database.CreateDocument(); document.PutProperties(new Dictionary { { "firstName", "John" } });
// Update a document. document.Update(rev => { var props = rev.UserProperties; props["firstName"] = "Johnny"; rev.SetUserProperties(props); return true; });
I want the same thing in React-Native format .
If you provide this is simple steps that would be a great help for me , Thank you