Making document private

20 views
Skip to first unread message

parvez....@decurtis.com

unread,
Apr 28, 2017, 9:55:29 AM4/28/17
to Couchbase Mobile


For an iOS application backed by Couchbase lite, how can we make a document as private? Here private means, the document will be stored locally but will not sync to the couchbase server. At iOS end, I am using below code snippet to apply a filter:
database?.setFilterNamed("MyFilter", as: { (revision, params) -> Bool in
            
            let typeParam = params?["type"] as? String
            let typeString = revision.document?.property(forKey: "type") as? String
            
            if typeParam == typeString{
                return false
            }
            else{
                return true
            }            
        })
        
        pushReplication?.filter = "MyFilter"
        pushReplication?.filterParams = ["type": "MyModule"]
let myModule = MyModule(forNewDocumentIn: database!)
        myModule.moduleDiskPath = "somePath"
        myModule.moduleName = "some name"
        do{
            try myModule.save()
        }catch{
            print("Encountered error: \(error) while saving module information")
        }



What I have observed is that the document with type "MyModule" is also getting synced to the Couchbase server but the expected behaviour is the documents should not sync. I am using Couchbase lite version: 1.3.1 (build 6)

Is it necessary that we also need to define a filter function at sync gateway end as well? The replication type is "Continuous".

How to resolve this issue?

Jens Alfke

unread,
Apr 28, 2017, 10:28:04 AM4/28/17
to mobile-c...@googlegroups.com
This should work; we have tests for it. The only thing I can see that you could be doing wrong is in this line:

let typeString = revision.document?.property(forKey: "type") as? String

Don’t go through the document to get the properties; get them directly by calling `revision.properties[“type”]`. This CBLSavedRevision object is a bit unusual in that it's constructed on the fly by the replicator (wrapped around the raw revision data), and I don’t think it has a CBLDocument object backing it up.

—Jens

Traun Leyden

unread,
Apr 28, 2017, 2:28:58 PM4/28/17
to mobile-c...@googlegroups.com
What about using a Local Document here?


--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchbase+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/FDC68752-D318-4550-A0AD-FD0D5CD296B1%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Apr 28, 2017, 7:53:18 PM4/28/17
to mobile-c...@googlegroups.com

On Apr 28, 2017, at 11:28 AM, Traun Leyden <traun....@gmail.com> wrote:

What about using a Local Document here?

That works too, but they use a different API and are very limited in functionality (can’t be queried, no models, etc.)
They’re a handy place to dump a few key/value pairs for things like local preferences...

—Jens

parvez....@decurtis.com

unread,
May 1, 2017, 3:43:53 AM5/1/17
to Couchbase Mobile
I have tried the above mentioned suggestion 








revision.document?.properties?["type"] as? String

but still then the intended document is getting synced to the Couchbase server. I would like to repeat once again here that at sync gateway end there is no filter function written.

Thanks

parvez....@decurtis.com

unread,
May 1, 2017, 9:58:24 AM5/1/17
to Couchbase Mobile
I ended up having a separate couchbase database (local) with no push-pull replication associated with it. This way one can store information that is totally private and will not be synced to the couchbase server.

Jens Alfke

unread,
May 1, 2017, 12:17:23 PM5/1/17
to mobile-c...@googlegroups.com

On May 1, 2017, at 12:43 AM, parvez....@decurtis.com wrote:

but still then the intended document is getting synced to the Couchbase server. 

Set a breakpoint in the filter function and look at what it’s doing. It must be returning true when you don’t expect it to.

I would like to repeat once again here that at sync gateway end there is no filter function written.

That doesn’t matter for a push replication. The filter runs on the client side.

—Jens

Reply all
Reply to author
Forward
0 new messages