Spring reactive mongodb get subdocument - spring

My application has users and servers, every user can have multiple servers. I would like to get a server by giving the user Id and the server name.
Example database:
{
"_id" : ObjectId("5a168093abfc7d0da1eaf039"),
"email" : "test#test.com",
"name" : "asdf",
"password" : "$2a$10$sC2WjxBdmsmN/x4GI7rgS.HBr4C.W8oxFJ7p/WMC24YcoARX8pNba",
"is_admin" : false,
"servers" : [
{
"_id" : BinData(3,"5xEk0HAIc7P+JevFrKP5lQ=="),
"name" : "asdf",
"host" : "asdf",
"ssl" : true
}
],
"_class" : "com.stack.database.main.model.User"
}
The user id is unique and the server name is unique per user. I would like to get the Server model(The servers list, not an actual #Document but a sub document) by giving the user id(5a168093abfc7d0da1eaf039) and the server name(asdf). I would like to use the repositories for this, the ReactiveCrudRepository repository.
I know I can get a user with a certain certain server name by using this in the UserRepository:
Mono<User> findByServers_Name(String name);
But I want to get the server model based on the user id and server name. I was thinking about something like this:
Mono<Server> findByIdAndServers_Name(ObjectId id, String name);
Note that this also has to be in the user model because the Server has no repository because it is a sub document.
How can I can a server model based on user id and server name with reactive crud repositories?

Related

How to store search data in redis db for caching to gain maximum performance improvement

We are implementing a online book store where the user can search books by filter,price,
author, sorting etc..Since we have million's of records in database(mysql) the search query
becomes slow. SO improve performance we are planning to implement caching mechanism using redis . BUt i am struggling to determine how to store the search data in redis db.
For example:-
If the search criteria is below:
{
searchFilter:
[
{
"field":"title",
"operator" : "LIKE",
"value" : "JAVA"
}
]
}
Then we will fetch data from from mysql db using above json. Then we are storing the data received in redis server.
In redis server we are using above json as "key" and all the books as value i.e
:
{searchFilter:[{"field":"title","operator" : "LIKE","value" : "JAVA"}]} : booksList
Now say some other user again fired a search request as below
{
searchFilter:
[
{
"field":"title",
"operator" : "LIKE",
"value" : "JAVA"
},
{
"field":"price",
"operator" : "GREATER_THAN",
"value" : "500"
},
{
"field":"price",
"operator" : "GREATER_THAN",
"value" : "500"
}
]
}
Then again we will fetch data from from mysql db using above json. Then we are storing the data received in redis server so that for next request with same search critria
we will get data from redis cache.
In redis server we are using above json as "key" and all the books as value i.e
:
{searchFilter:[{"field":"title","operator" : "LIKE","value" : "JAVA"},{"field":"price","operator" : "GREATER_THAN","value" : "500",},{"field":"price","operator" : "GREATER_THAN","value" : "500"}]} : booksList
So my question is using the json search criteria as key in redis is good idea?
If yes, then for every search request criteia having any small difference if we store the data in redis then caching server will consume lot of memeory.
So what is the ideal aproach to design our redis cache server to gain maximum performance ?

YouTube V3 LiveBroadcasts: list issue with service account credentials

I was trying to make list api call to get the list of upcoming live streams. But when I was using service account credentials the API is always responding with below status.
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.liveBroadcast",
"message" : "The user is not enabled for live streaming.",
"reason" : "liveStreamingNotEnabled",
"extendedHelp" : "https://www.youtube.com/features"
} ],
"message" : "The user is not enabled for live streaming."
}
Please let me know if I have to assign any specific role in IAM for this particular service account to allow this API to work.

Spring Boot 2 Actuator - versions aggregation from multiple microservices

We have a Spring Boot 2 REST service app consisting of multiple micro-services. ELB is used for service registration and discovery, e.g. there are services available at
http://<dev-env>/api/serviceA/actuator/info
{
"app" : {
"name" : "App Name",
"description" : "App Description"
},
"git" : {
"branch" : "origin/brancha",
"commit" : {
"id" : "204f7a0",
"time" : "2019-07-10T11:09:13Z"
}
},
"build" : {
"version" : "0.0.1-SNAPSHOT",
"build" : {
"version" : "v_0.1.151"
},
http://<dev-env>/api/serviceB/actuator/info
....
Every service uses SB 2 Actuator.
How can we aggregate this version information from two or more micro-services into single page(kind of dashboard)? Are there any ready solutions?
In your dashboard application just open a http connection and query all the microservices actuator endpoints. There are tons of ways to get started. You should choose one that you are comfortable with.

Protecting data in elastic search

I have a elastic search engine running locally with an index which contains data from Multiple customers. When a customer makes a query, is there a way to dynamically add Customer Id in the filtering criteria so a customer cannot access the records from other customers.
Yes, you can achieve that using filtered aliases. So you'd create one alias per customer like this:
POST /_aliases
{
"actions" : [
{
"add" : {
"index" : "customer_index",
"alias" : "customer_1234",
"filter" : { "term" : { "customer_id" : "1234" } }
}
}
]
}
Then your customer can simply query the alias customer_1234 and only his data is going to come back.

How to create a store and get store id in mail chimp for drupal commerce?

I need store id(store_id) to pass the value in this API.
/ecommerce/stores/{store_id}/carts
You need to first add a store to MailChimp using below API. Whatever id you pass in this request will be your store id for the subsequent requests.
https://usX.api.mailchimp.com/3.0/ecommerce/stores:
{
"id" : "store_001",
"list_id" : "205d96e6b4",
"name" : "Freddie's Jokes",
"domain" : "www.freddiesjokes.com",
"email_address" : "merchandise#freddiesjokes.com",
"currency_code" : "USD"
}
You can further check the Api at:
https://developer.mailchimp.com/documentation/mailchimp/reference/ecommerce/stores/

Resources