Couchbase mobile for social networking?

#1

We are creating a mobile app based on social networking.It will contain social networking features like profiles,newsfeeds,followers etc.Suppose we manage the local db by purging and compacting.

Is Couchbase mobile good for such app?We don’t need to sync all the data like comments.We want to get the comments data only when user clicks on comments button.Also we need to add search for profile functionality.Can we achieve this by creating a REST service layer using node.js sdk?

We think couchbase mobile is simple and easy to work on.So please guide us.

#2

you can use Push Filter Replication: Click here: http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/couchbase-lite/native-api/replication/index.html

Do you want to create a REST end point service that you can query your current users in Couchbase to add or follow?

#3

@househippo
Thanks for your reply.
I think my question is not clear.
Comments are stored in server and we want to get the comments from server only when user clicks the comment button.I think for that we need filtered pull replication. But filtered pull can be achieved only by channels which we can not do in our example.

And yes we are thinking about creating a REST end point service that can query current users in Couchbase to add or follow.Can we do this?

#4

The pull replication on CBL can be a one-time request also i.e. when a user clicks a button or on a time interval.

Yes, you can create a REST end point that uses N1QL(SQL++ for JSON) to query Couchbase Server.
It can scale to 100,000+ unique queries per seconds, or 1,000,000+ of cached query per second.(List of users do not change that often)

N1QL is pretty cool b/c you can query JSON with nested Objects and Arrays & even do JOINS on two or more different documents.

DEMO: http://query.pub.couchbase.com/tutorial/#1
Docs: http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-language-reference/index.html

#5

Why not? You can route the comments for post XX into a channel named something like comments-XX, and give access to anyone who has access to the post. Then the client can easily pull that one channel.

#6

@jens
I am new to couchbase.Thanks for your help.Still we have some questions-

How to pull replicate only one channel?

  1. We have documents called post in our project.users can like posts.we have timestamp property in each post document.How to pull newest post first?

  2. Suppose a post document is purged from local db.Same post is liked by other user then this post document is updated. so it will be replicated back to the device where post document is purged.How to avoid this?

  3. How to fetch posts by most likes(trending feature)?

  4. Is there any cb lite api function to remove user from channel like removeChannel?if not how to remove user from specific channel?

#7

How to pull replicate only one channel?

Through the Replication.channels property. Set this to an array of channel names you want to pull.

How to pull newest post first

Replication doesn’t really have a deterministic order. It’s basically in forward order of mod date (i.e. least recently modified docs first) but everything’s being downloaded asynchronously so they may not end up being added to the db in a predictable order.

so it will be replicated back to the device where post document is purged.How to avoid this?

You can’t really avoid it. You could work around it by keeping a list of docIDs that you’ve purged, and re-purging them if they reappear.

BTW, about “Same post is liked by other user then this post document is updated”: That’s generally not a good way to do it. It’s going to create a lot of potential conflicts — think if dozens of users like a post at almost the same time, and each tries to push its change to the post doc. Instead, a Like can be a separate doc that refers to the post. Then you use a view to find/count the likes for posts.

How to fetch posts by most likes

You can use a view with a reduce function and grouping, to get a mapping from postID to like-count. Then you can sort that by like-count.

Is there any cb lite api function to remove user from channel

Use a PUT to update the user info (/db/_user/username) via the admin REST API. But it’s more common to have documents grant channel access to users; then updating that doc can remove the grant.

#8

Is there any way to pull newest post first?
What if we create REST endpoint in node.js and using N1QL we can send the ids of docs of new posts to the client?Then client can pull those docs by id.Is it possible?

#9

One technique we’ve suggested before is to have time-based channels, and assign posts to those channels based on their dates. For example, channels named 2016-01, 2016-02, etc. Then the client can pull the most recent channels first.

I’ve done some work on a feature to let apps run queries on the server and pull the resulting docs, but it’s not in a release yet. (It’s difficult to filter the query results to make sure they don’t expose documents the user shouldn’t have access to.)

What you’re suggesting sounds similar; I think it’s workable.

#10

@jens , I have been thinking about this the past couple of days. I’m not a fan of lots of little docs with “likes” and comments being replicated to lots of users and then aggregating all of them at the CBL level. What do you think about directing all the likes to a “admin-like” channel and having a server side app do all the aggression and pushing down a single doc with sum total every XYZ seconds. This way everybody roughly will see same total and docs amount passed down to CBL is a fraction of all the likes docs created. Thoughts?

#11

That sounds feasible.

It will lower the amount of work done on the client (saves aggregation), but increases the amount of work on the server.

The total number of documents on the server will be larger. The clients will have fewer documents, though.

(In my own spare-time project I don’t do it this way, because I want as little work done on the server as possible; in the future I want to go P2P.)