Why can I not see newly inserted JSON documents? - javascript

Why can I not see newly inserted JSON documents?????
Couchbase 4.5
JavaScript
AngularJS
Node.JS
Express Server
I have a web application, which performances data maintenance. The user will select from a menu, which data to manipulate. The user has the option of inserting, updating, or deleting once the web application retrieves the data. I ran several tests of the application and discovered an issue.
Background to the Issue:
Couchbase server resides on Local Computer
Application written using JavaScript, AngularJS, NodeJS running Express Server
User enters new data into the web application. Once completed, the user will depress an update button, which determines if the user wants to insert or update a JSON document. The web application determines the user is adding new data to the database. The web application formats the data into the appropriate JSON document format. The web application sends the data to the database using the REST paradigm. The database returns a success status back to the web application. Upon recognizing the successful database update occurred, the web application retrieves the data in order to display the must current data.
Issue:
After reviewing the new retrieval of the data, the record just inserted does not display. After waiting a few minutes, I re-retrieved the data again. The newly inserted data appears. I ran the process several times. Each time I could not immediately retrieve the newly inserted data.
Questions:
Can someone explain to me why a JSON document of less than 1000 characters will not retrieve after insertion?
Will I need to insert the new inserted data into my existing result set? If so, why when the data resides in the database?
TIA

I guess you are talking about N1QL or views querying, if so, you probably operating on default consistency levels, which trades immediate update for performance. If that is critical at point in your application, you should pick different consistency level.
Overview of the feature: http://developer.couchbase.com/documentation/server/4.5/architecture/querying-data-with-n1ql.html
Blog post with video demo: http://blog.couchbase.com/2016/july/n1ql-scan-consistency-including-new-atplus-video
N1QL API to change consistency: https://github.com/couchbase/couchnode/blob/771ebf78f82b437999e13b05e4699c88a02dc8d3/lib/n1qlquery.js#L71

Related

Caching Firebase data for multiple collections - how can I know when anything has changed?

I'm using Firebase to allow users to save certain information about their logged-in profiles. In total I have 4 different collections, and all of which contain UID-matching documents.
When my site loads up, I need to immediately access data from all 4 collections for a given user's UID. This means that right now, whenever a user reloads my application they generate 4 get requests. However users of my application tend to not change their stored information very often (perhaps once every 20 or so times they load the application), so there's really no need for this data to be re-requested every time.
I've already taken steps to cache all of this data within the user's browser local storage, but here is where my problem lays: how can I know when the data I have cached is out of date?
In the past I've created similar cache mechanisms which ultimately rely on a 'version' flag. Both the data source and the user's local storage contain a 'version'. When both match, the application knows that it has the latest data, however when they are out of sync, the application knows it needs to re-request the data. The 'version' flag on the data source is ultimately changed every time an update occurs which impacts the user in question.
Ideally I want to end up with this flow:
User loads application.
Application compares local data version with version contained in Firebase.
If versions match, use local data.
If versions do not match, request all data.
Is it possible to do something like this with Firebase? Right now I can't see this possible without having to generate an extra set call every time the user's data is modified to change this version flag.
If this isn't possible, how can I know when a user's data needs updating without using up multiple requests?
If it helps, I'm using Firestore and this is a web application with no backend.

How to write a web application where updates by one user are immediately visible to all users?

I am trying to write a web application that displays to users a hierchical tree. Users can add,delete, and update the tree but the tree should look the same for all users. My first thought to save the state of the tree (i'm using JSON to represent the data in the tree) in a database but, what happens if there are a million/billion/etc number of people using the application? How do you make sure that all users are physically seeing the same thing if additions/updates/deletes could be going on simultaneously?
Something like signalr would would help:
http://signalr.net/
What can you do with ASP.NET SignalR? SignalR can be used to add any
sort of "real-time" web functionality to your ASP.NET application.
While chat is often used as an example, you can do a whole lot more.
Any time a user refreshes a web page to see new data, or the page
implements Ajax long polling to retrieve new data, is candidate for
using SignalR.
It also enables completely new types of applications, that require
high frequency updates from the server, e.g. real-time gaming.

How to access multiple database dynamically using Entity framework 6.1(Power Tool Beta 4) with ASP.NET web api

I've created a project using Asp.net Mvc 4 => Web api...
I have integrated Angularjs in it. and so I'm using single page app.
I'm also using entity framework 6.1.
For Database connectivity, I'm using Entity framework Power tool beta 4 by which I target particular DB and generate DBcontext.
Now scenario is:
There is one other application by which end user can register himself. When he does it, new Database is generated into Database server with "ProjectName+ClientName" name eg. MISSteve,MISJohn...
This new user entry goes into MISDBManager Database which is already there in Database server with new connectionstring and new user.
So, This MISDBManager has clientName and relevant connectionString.
So overall. In Database, One MISDBManager which has different registered users with DB Connection strings.
eg,
(ClientName) - (ConnectionString)
BV - data source=pdev-3\xyz;initial catalog=MISBv;integrated security=true
Steve - data source=pdev-3\xyz;initial catalog=MISSteve;integrated security=true
Now My problem and question is,
When I run my application, logging page comes. user enters his credentials. Now With Power Tool Beta 4, through reverse engineering, I have already generated MISDBManagerDBCOntext against which I check whether credential is valid or not. Till here everything works perfectly fine.
But what I want is, If username & password are valid, I want to connect that valid user to his relevant DB.
As I have stated I'm using EF 6.1, PowerTool Beta 4 and with Reverse Engineering I can only target fixed client. Which is not valid for my Project.
I want to connect valid client to his one DB (generated & stored with different tables into Database server).
with static approach, I can target one client. But when it comes to dynamic approach I dont't know how to do it.
Means, As shown here if BV(ClientName) gets logged in, i can redirect him to Dashboard because I have generated his fixed MISBvDBContext.
But If other user gets logged I can do it.
If i'm having thousand users I can't generate thousand DBcontext. so dynamic approach is needed to connect client to his Database.
Please help me to get this things done. Please let me know if other way is there to connect client to his DB.
Help would be greatly appreciated.

How can I write data to and update HTML5 cached web pages while working offline?

In the application I am writing, a user captures information about a person via an online form. When they have completed the form they save their work, repeating this process several times in a session. When they hit 'Save and End Session' they are returned a list of the several person instances they have just saved, all data being saved to a server.
I wish to replicate this functionality in an offline app. Using HTML5 I understand how to cache pages, and how store the JSON form data in localStorage using raw Javascript (or perhaps Angular.js cache).
But is it possible to dynamically update cached webpages with cached data while offline? how, for example, can I write the the cached form data to a cached copy of the list page, updating that page with the data just produced, all during the offline session?
I cannot find an answer to this one. All suggestions are much appreciated!
If I understood this correctly, you want to dynamically update the html view while offline.
If you are using Angular, this is pretty simple.
You just have to cache also the JS controller, not only the html file (set it in the cache.manifest). The page will have the same functionality as the online app then. But if you want to send the stored offline data back to the server when offline, you can write a simple code that will:
Save the parameter in localStorage, which will mark if the data was saved while running online/offline app (you can recognize onine/offline by sending AJAX request to an existing part of the app, which is not available offline (so not cached one))
When app runs then in online mode, it will collect all the data stored offline and send it to the server

Backbone.js and CakePHP

I'm interested in implementing Backbone.js for some of the more repetitive in-page CRUD structures in our application (which is built on the CakePHP framework). I've been trying to get a hold on Backbone while figuring out how it would work in conjunction with Cake, and I"m a bit lost when it comes to separating the duties of the two sides.
Am I trying to jimmy something into my site that doesn't need to be there? Is there precedence for this kind of stack structure? I'm all ears at this point.
I'm actually working through the same situation right now (though with Python/Flask, but the same concepts should apply to any serverside language). Here is how the workflow for a page goes in my application. Just a note that I do NOT follow the single page application format; in my app, each major page is a full reload.
User requests a page, say a list of companies, /companies/listing/
Server does the routing, loading the correct controller
Controller loads first X companies from DB
Companies are encoded as JSON
Other meta data is loaded (such as total number of companies) and turned into JSON
The list page template is loaded and the JSON popped into a <script> tag within the template. Note here I do not fill in the listing table or anything along those lines, I let Backbone do all of that. I fill in the JSON here so the client doesn't have to make a second request for the initial set of companies
The list page is sent to the client. The server is done for now
The client has all the data it needs to start, so I take the JSON and pass it to my Backbone.View for the listing page
The view creates a collection for the models and manages a set of sub-views that represent the entries in the list
Any other processing/view creation happens such as the creation of pages, prev/next buttons, etc.
If the user clicks to the next page of companies, I fire an AJAX query to the server (/companies/listing/page/1 or something) which returns a new JSON string with a new set of models
Send the new set of models to my Backbone.View which refreshes everything
So really, the server is used for nothing but the actual loading of data, and the initial send of the template. I like this because it'll allow me to easily hook up new frontends (say, an iPad app or something).
For a form, in really broad strokes, I do something like this:
User requests form, /companies/edit/1
Server does permissions checking, loads entry, sends template/JSON to client. Server does not fill out the form with the data
Client uses JSON to fill out the form
Client modifies form, hits submit
All of their changes are applied to the model, the model is turned into JSON and sent to the server using AJAX
Server does validation and either sends error messages (in JSON) to client or updates the database and sends a success message
So, again, those are really broad strokes on how I've done it. In general, I use the server to grab data from the database, do server side validation (can't trust the client heh), and update the database.
If you have some specific questions, I'd be happy to try to share what I've learned so far.

Categories