Views in multi-node Couchbase cluster explained - couchbase

I am new to Couchbase.
I have a 2 node Couchbase environment, and I have 20 documents (Articles in my application) stored in a bucket. I believe that there are 5 articles living physically in node 1 and the others are living in node 2 because when I shut down node 1, there are only 15 articles in my application's list.
I have an 'ordered by postdate' list in my application which I get results from a view like this: ...emit(doc.postdate)...
Now, for some reason, the list in my application is always incorrect that some of the articles are not in the right position (not ordered by the post date).My only guess is that: node 1 has an index for the 5 articles and node 2 has an index for the other 15, they both order by the postdate field correctly in there own index, but after my application (using a .NET client library) get 5 from node 1 and 15 from node 2, it just 'concat' the two list into a full list 20,that's why I saw the wrong order in my application's article list.
So please tell my guess is wrong and my misunderstanding of Couchbase server, and also any other reasons I got a wrong ordered list? Any detailed information from the couchbase's architecture perspective will be really appreciated.
Thanks very much in advance.

Make sure you are ordering correctly. There are parameters to try ascending or descending to see if it makes any different order (if not, that means you are not using view ordering correctly).
See Ordering results
Also please provide your view mapping code.
e.g.
function (doc, meta)
{
...
}

Related

is storing frequently used data in json in mysql worth it?

in vue.js app the main focus is working with prospects. prospects have many things like contacts, listings, and half a dozen other objects/tables.
they also have interactions, which could have 30 or more per prospect, while most things like emails or phones would have 1-3 results. I load 50 prospects at a time in to the front end
I'm trying to decide if loading it all into the front end to work 50 prospects at a time is a good idea, or if i should have a json column with interactions as part of the prospects table that i would update each time an interaction is saved, with minimal info like date, type, subject...
it seems like an extra step (and duplicate data, how important is that?) to update the json column with each interaction, but also seems like it would save looking up and loading data all the time
I'm not a programmer, but have been teaching myself how to do something i need done for my business with tutorials and youtube, any opinions from those who deal with this professionally would be appreciated
also, if anyone wants to tell me how to ask this question in a better formatted way, I'm open ears
thanks
Imagine if you have 1000 data, but you are sending only 50 of them, and your user do a filter by price. Will you display only the filtered data from 50 or 1000 of them?
That depends on whether you want to expose all 1000 data to the front end. It's a choice between that, and calling your server api everytime.
If you are calling the server, consider using a cache like Redis to store your results .
Pseudo code.
Request Received
Check Redis Cache - Redis.get('key')
If key exist - return cache.
Else -
check mysql for latest results.
Redis.set('key', latest results);
CreateRequest Received
- Write to mysql
- Redis.delete('key') // next request to view will create new cache with fresh data.
Your key can be anything like, e.g your url ('/my/url')
https://laravel.com/docs/8.x/redis

Logging every Create/Update/Delete

I need to log every changes through the application. Every changes will be connected to specific user, but connection can be null as well (add new item by remote API).
Let's imagine that some user adds new item. Here my problem starts... :) I don't know, how to store it properly and also don't know right solution. My ideas:
1 MySQL record
id(bigint), created_at(timestamp), user(int), changes(json?/or something else?)
JSON would be like:
{
table_name: 'item_name',
id_item: 1,
note: '' // optional
}
I don't know if this method is right for this use case. When I am writing this, I am thinking about id as uuid not int. Could it be?
2 JSON
Save record by record to the json file and after some size create new one. Records would be the similar structure.
I really don't know what method is the best for this use case. I'll be appreciate for a bit help. Thank you. Have a nice day. ;)
What you are describing sounds similar to functionality provided by temporal tables, a feature built into recent versions of MariaDB. You may want to look into that before you start inventing your own audit logging.

Access relationship looping example

I am struggling with some basics of MS Access 2010/2013. I am not sure if I did hit the limit of it or if I am just using the wrong procedure. I will explain what i need.
Take for example 5 items in a shop, where 3 are items and 2 are a combination of items.
They need to be presented in the same matter, i.e. the combinations of products (bundles), needs to have a number in the same series as those it contains. See figure below:
So far, I created 2 tables. 1 for stand alone products and 1 for bundles. Bundles should be able to include other bundles (This is where i get the problems).
If someone orders, lets say, 10 times Items 5, I need Access to count how many Motherboards (Item 1), how many CPU (item 2) etc. I need a full list of those items, so i hopefully should get a list that says:
10 x Motherboard
10 x CPU
10 x Cabinet
So i don't have to dig into each bundle. Hence, as i see it, the relationsship runs in sort of a loop.
I identify the items to be either a combination or product by a column with "yes/no".
If you have any suggestions, let me know, or if you think i hit the limit.
An alternative method is welcome, as well as a sample of a simple Access database.
For the record, the system is gonna be used for huge machines, creating lists of bolts, nuts, electrical equipment etc. The above is only to explain my thoughts.
Best Regards, Emil.

Solr index multiple tables from MySQL

I have following mysql tables
1. user(user_id,email)
2. tweets(tweet_id,user_id,tweet)
3. tags(tag_id,tag)
4. tweets_tags(tweet_id,tag_id)
I want to show current user's tweets under "My Tweets" Tab in application. I want to get following data from Solr
user_id
email
tweet where user_id=x
tags where tweet_id=xx
How to index those mysql table on Solr? I only what to know the code of schema.xml and data-config.xml for Full/Delta import.
Note : I am not asking about MySQL connector etc, I have done already.
The use case you've described doesn't seem to justify using solr. You would just make sure you have proper keys and indexes and do it in mysql directly.
If for some reason you MUST use solr, you could probably prepare all the data and feed it to solr in a tag/tweet/user structure like this
user1 - tweet1 - tag1
user1 - tweet1 - tag2
user1 - tweet2 - tag1
and so on.
Then from solr you query by user, and then sort and group by tweet and then tag.
However I must state again that the solution I just described is implemented much safer with a higher confidence on the result by using plain sql.
Should you provide more details on your desired outcome, I'd be happy to suggest the database structure along with the necessary foreign keys and indexes and the queries you need to get your data out.
If you are using DIH (dataimporterhandler), I guess that link should be the solution for you:
Import with sub entities
If you have problem with writing the exact configurations, please let me know, I can assist you.

mysql query all sub-accounts and their sub-accounts and so on

I have one table like this
account_id (INT)
inviter_id (INT)
Now, logged in user with account id 5 wants to see the logs that related to all of his invitees, directly and indirectly, as this table may represent nested hierarchy of unlimited depth.
How would I do that with MySQL?
I accept a solution in PHP/C/C++/C# (:
Actually I've looked for it here and at google and couldn't find anything for that particular case, as everyone try to have nested menus at their website and ask about it.
I've been thinking about simply querying for all accounts in the database (there are about a few hundreds) and from there simply build a tree, or something, but then again I have to stay synced with the database.
So to stay synced with the database I've thought about querying the COUNT() of the accounts in the table, but, what if I need to change an inviter'd (maybe deleting one)?
Anyway, I could appply the rule of "not changing inviter" - if I'd do that, then COUNT() would work I think - is there any better approach to that kind of issue?
you can take a look at my answer(s) here if you like:
Print hierachical data in a parent child form unordered list php?
or here:
Mysql Recursive Stored Procedure...Limit 0 reached...can't change the max_sp_recursion_depth variable
or here:
Multi-tiered Comment Replies: Display and Storage
or here:
MySQL Hierarchical Structure Data Extraction
hope it helps
Check this out, this might give you some ideas: http://www.ideashower.com/our_solutions/create-a-parent-child-array-structure-in-one-pass/