I have a CouchDb instance running a peruser database configuration.
Each user database generated (when a user is added to the _users database) needs to have the same design documents with view/list logic etc.
What is the defacto way to add the design documents to the database upon database creation? Is it simply to add them after a successful user creation request? Or is there a more elegant way of doing this in CouchDb?
There is not a mechanism for initialize newly created user databases, you should include it in your user creation logic.
If you want to decouple user creation and db initialization, I suggest you to explore the following strategy
1 - Create a template database and place on it your design documents that should be applied to every user db
2 - Listen continuously _db_updates endpoint where db level events will be notified. This library can help you.
3 - When a db that matches the user db name pattern is created, you can trigger a replication from the template database to the newly created database using the _replicate endpoint.
If you plan on using the Follow npm module as #Juanjo Rodriguez suggested, please consider using the Cloudant's version. The Iriscouch's version (the one pointed by #Juanjo Rodriguez) is way out of date. For example it doesn't support CouchDB v2.x among other issues. I worked with the Cloudant's team to improve all this these last days and they just released the updated npm package yesterday here: https://www.npmjs.com/package/cloudant-follow?activeTab=versions
The 0.17.0-SNAPSHOT.47 version embarks the patches we worked on so don't use the 0.16.1 (which is officially the latest).
You can read more about the issues we fixed here:
https://github.com/cloudant-labs/cloudant-follow/issues/54
https://github.com/cloudant-labs/cloudant-follow/issues/50
https://github.com/cloudant-labs/cloudant-follow/issues/47
Related
I have been reading docs and articles on pouchdb/couchdb/cloudant. I am not able to create this simple architecture in my head. I need help!
So there are many users on the app. Each user has a separate database (which I read is the approach in pouch/couch/cloudant setup).
Now lets just focus on a single user. This user has some remote data already present on our server(couchdb). He has 3 separate docs stored.
He accesses docs 1 and docs 2 from browser 1. And docs 2 and docs 3 from browser 2.
Content in both the browsers must be in sync.
Should I be using Sync api of pouchdb? But as I read, it sync's the whole database. How can I use this api to sync only a subset of the central database. Is filtered replication answer here?
And also I don't want to push both the docs in a single call. He can access docs as he needs.
What is the correct approach to implement this logic with pouch/couch databases. If you can explain with a little code, that will be great. I just need basic ideas.
Is this kind of problem easily solvable in upcoming releases of CouchDB 2.0 and PouchDB-find.
Thanks a lot!
If you take a look at the PouchDB documentation, you should see the options.doc_ids. This parameter let you setup a replication on certain document ids. In your scenario, this would be solving your problem.
Here is my situation. I have an extensive REST based API that connects to a MongoDB database using Mongoose. The API is written as a standard "MEAN" stack application.
Currently, when a developer queries the API they're always connecting to the live production database. What I want to do is have an exact duplicate database as a "staging" database, where new data will be added first, vetted over a period of time, and then move to the live database. Then I want developers to be able to query either one simply by modifying their query.
I started looking into this with the Mongoose documentation, and it appears as though the models are tied to the DB connection, and if I want to have multiple connections I also have to have multiple models, one for each connection. This would be a nightmare of WET code and not the path I want to take.
What I want to do is not touch any of my code at all and simply have a switch that changes to the proper database for a given query. So my question is, how can I achieve this? Is it possible? The documentation seems to imply it is not.
Rather than trying to maintain connections two environments in the same code base have you considered setting up stage version of your application? Which database it connects to could be set through an environment variable or some other configuration option.
The developers would still then only have to make a change to query one or the other and you could migrate data from the stage database to production/live database once you have finished your vetting process.
I need to sync some document from Cloudant server to my iOS in swift language.
For that I use this official library
https://github.com/cloudant/CDTDatastore#overview
I need to understand how replicate only user documents.
I need to figure out the correct road.
Imagine you a ticket assistance system of a company.
All users can create the ticket and this is save in cloudant/couchdb server.
When the user uses a mobile platform, I would just like to synchronize him ticket
how can I do it?
Thank all
CDTDatastore is designed to sync the whole database, and cloudant/ couchdb doesn't provide a per document ACL. In order to only sync a specific users data you either need to use a filter function, which will significantly hit the performance of the replication, or use the one database per user model.
Good day! I have created an application using nodejs + mongoose and now I want to make something like a superuser application. I need my admin panel application to connect to the same database. So, i have a question.
Should i store the same Schema file in both applications to have an ability to use my Schema methods? In other words, what is the best way to create one more API using the same db?
Thank you!
If I'm not mistaken, why not create another service that only interacts with the database? That way, the systems will refer to the same schema/DB regardless of which application you want to connect to it. So the superuser application and the normal application will just query the DB microservice that interacts the database.
Pro: source of truth for the schema for all applications and the DB queries will just be API calls
Con: additional overhead in creating your ecosystem
If you are using the same DB from two different applications, you will want to make sure those schemas are the same between the two. If one changes its inputs, the other might need to change its display (or risk not expecting all that information). Keep all this in mind during your release process.
I would suggest making the schemas an external library to both, or have the admin panel require the current app. You'll avoid getting two sets out of sync and know to look at one place for the schema definitions.
I am using ServiceStack to build my API/Service. Database communication is done through OrmLite which is supported by ServiceStack. Database connection is being used through IDbConnectionFactory.
My database (SQL Server) is being updated through SQL Replication (receiving data updates from another database). I want my cache (service level) to be cleared once a update is made to the database through any source.
Is there any way i could use SQLDependency or any other mechanism to always get the updated data along with using cache?
Normally, you would use something like ServiceBroker to get notifications for database changes.
Try checking out this other question, someone provides an answer with SQLDependency: How to monitor SQL Server table changes by using c#?
I'm new to ServiceStack myself so I'm unsure if they have within their framework something that would do this with minimal setup.