How to delete telemetry and attributes of entities when entities themselves are deleted - thingsboard

I didn't find any information in the official documentation about whether the telemetry and properties are deleted after the device is deleted.
However, when I check the database after deleting the device, the telemetry and attributes of the deleted device are still present and have not been deleted.
I want ThingsBoard to remove both the telemetry and the attribute values of this device when the device is deleted
ThingsBoard version : 3.2.2

You can either delete the device attributes/telemetries via Database query or Administration REST API. I would recommend the second option:
https://thingsboard.io/docs/reference/rest-api/
e.g. there is in an endpoint for deleting device attributes:
<TB_HOST_URL>/swagger-ui/#/telemetry-controller/deleteDeviceAttributesUsingDELETE

Related

Realm Sync data resets on app reinstall

I have an iOS app which uses Realm locally and it works great, and my intention is to use Realm Object Server to enable:
Data sync across devices
Data restoration on app reinstall
I've been having a lot of trouble with the last one. The flow in my app is the following:
First, it tries to find a User in my Realm Sync. If a User exists, go to step 4. Otherwise, go to step 2;
Ask for the user's name, income and payday;
Get the user's userRecordID for iCloud and logIn to Realm Object Server.
Use the SyncUser's identity as the User entity identifier. Save the data I just asked (name, income and payday) to Realm;
Go to main app screen and let the user enjoy the app.
ROS is using cloudkit based authentication. The problem occurs if I follow steps 1-4 above, and then reinstall the app. I expected the previously created User to be retrieved in step 1, but instead all of its fields beside the primary key are set to blank values (name becomes empty string, income and payday become 0). Is this behavior expected? Is what I want to do within the purpose of Realm?
EDIT
Made the flow clearer after #AustinZ's answer.
"Data restoration on app install" is definitely a valid use case for Realm Sync. However, the flow you describe is problematic.
A synchronized Realm is identified by two pieces of information: a sync user and the Realm's path on the Realm Object Server (e.g. /~/my/realm). If you have the same sync user logged into multiple devices, and they each open a copy of a Realm at the same path, they are opening the same synced Realm and will stay in sync with each other.
However, to get the same sync user, a user needs to log in to the Realm Object Server from their device. You do this by creating a CloudKit SyncCredentials value using SyncCredentials.cloudKit(token:) and passing that credential to SyncUser.logIn(). The device will then communicate with the Realm Object Server, and if the log in succeeds, then the logIn() method's callback block will be invoked and will give you a SyncUser. That is the sync user you need to use to open Realms.
So:
You shouldn't be saving users or user info to Realms manually. We persist the relevant information automatically.
If a user deletes and re-installs their app, the app's documents and files are deleted as well, which means you shouldn't assume you can access a Realm's data after the app which created it was re-installed.
What you should be doing is, in step 3, using the user's CloudKit credentials and logging into the Realm Object Server as described above.
Please review our documentation for more information.

Query over firebase doesn't bring most recent values on cloud, but local on device

I'm using the firebase api as a database, and have the persistance enabled (this is mandatory, for I would like the user has the most recent information available offline).
The problem I'm facing right now is that when I make a query (wiht the query commands), the response I get is repsect with the local info of the device and never retrieve the info for the cloud.
How can I make to bring the info from the cloud when the user is online?
Thanks
The problem was I was making a observeSingleEventOfType and this only get the values of the devices. Once I changed to observeEventType it works!

Share database [core data] between different devices, not just the user's ones

What is the best way, to share a database between different devices, that are not just the user’s ones, but for example could be his friend’s phone. That means that iCloud is not an option.
Example:
 All of my data is app-user specific, so basically:
user logs into my app, do some work
then he can log in with the same acc on his friend phone and data should be the same
Is there an any way to upload the whole user specific database to some online storage provider (like firebase,… ) and then download it on another device and initialise core data stack, when the same user logs in on a different device?
Or is it the only way to sync data with the server and than preload the database?
You could simply upload the whole database file(s) and then download it on another device. The problem though is portability. You need to ensure that both devices support the same version of the database so they are compatible. To port the same thing to another platform is again a different story but doable when not using core data.
Then there is a problem of conflicts. Imagine you forget to log out from the second device and you open it after a week and the database is accidentally synced back to the server. This will make you lose all the data you created on your "main" device.
So in general it is possible to sync the whole thing but you will have loads of issues. You should create a server that supports all entities and works through ids (so you know the object was modified and not created) and date modified to be able to resolve conflicts.
Syncing data between multiple devices is the biggest reason to use something like Firebase. That's one of its primary purposes. You would use Firebase for data storage instead of Core Data, and it would automatically handle syncing between devices. You don't write code to upload or download anything, you just read and write Firebase data and it handles the syncing. It supports user accounts, so if a user logs on on a different device, their data automatically syncs to that device. There are numerous other options besides Firebase, of course.
CloudKit also syncs between different devices, but it's linked to the current iCloud account on the phone. Since you want in-app login, it's not so good.

Issue in Sync with soft delete enabled in native iOS (Azure Mobile services)

I am using azure mobile services on iOS platform and syncing with service ( soft delete enabled), when I delete some records using another device, _delete flag is set to true for that records in service database, but when I sync with iOS device, deleted records are still present there .
I have seen other questions on SO, but they did not solve my problem.
Any help would be appreciated.
EDIT :
I am using enableSoftDelete:true
DomainManager = new EntityDomainManager<TableName>(context, Request, Services, enableSoftDelete: true);
A new column _Deleted is setting to true after deleting from another device.
To enable soft delete on the .NET backend, you need to pass a parameter to the EntityDomainManager in your controller InitializeMethod:
DomainManager = new EntityDomainManager<TodoItem>(context, Request, Services, enableSoftDelete: true);
For more information, see Using soft delete in Mobile Services.

Storing usernames and password

right now I'm using Core Data - sqlite for database. And I have a few questions related to it.
I created a Modal with all the personal information of the user: username, date of birth, address, zip, state, etc... The password I'm using Keychain for login functionality. So, my basic question is:
Where is this information stored? Locally in the user's iphone? But what if I have millions of users, wouldn't that database file be too big? Is it safe? I mean, users can see information of another users?
How can I edit that database if not programatically in xcode? I mean, what if I want to delete some user or change some specific information.
Thanks.
Creating a local sqlite database on the device will only store the individual users info as each app is obviously stored on each device separately. Users won't see each others info.
You will need to edit data in the database programatically via the app (ie code written in xcode)
Keychain data will be stored inside a local db in the device. This is a shared db for several apps. So after you delete and reinstall the app, you will get the data. Million users may have their own devices. not logging in from a single device. The data in this keychain will be stored in the encrypted format. So you dont need to worry about the security.
In iPhone simulator, the data will be stored in ~/Library/Application Support/iPhone Simulator/<Version Number>/Library/Keychains/
If you want to edit or delete the item, then try the below tutorial
http://useyourloaf.com/blog/2010/03/29/simple-iphone-keychain-access.html
if you use Core Data - sqlite for database then every user(device) has their own copy of databse.
so don't worry about file size & information of other users.
And you can edit that databse only by your app or by app's background Process in case of Core Data

Resources