#MongoDB + Unity (Realms)
1 messages · Page 1 of 1 (latest)
Unity is saying i should use PartitionSyncConfiguration instead of SyncConfiguration(user);
but in the MongoDB website it says its deprecated
they still have it though right?
should work fine
btw Unity has its own system now with each player stores their own data, also comes with Auth
but i need the information in the web
the unity system is cloud
yeah but you still wouldn't want to store your connection string inside of Unity
if someone decompiles your code they will have it
hmm bet
yeah i dont want that xD
let me show u what i got
using UnityEngine;
using Realms.Sync;
using Realms;
public class MongoDBManager : MonoBehaviour
{
private async void Start()
{
// Configuração da instância Realm
var app = App.Create("application-id");
// Logue com as credenciais do MongoDB Realm
var credentials = Credentials.EmailPassword("mail", "pass");
var user = await app.LogInAsync(credentials);
// Abra uma conexão com o Realm
var configuration = new SyncConfiguration(user);
var realm = await Realm.GetInstanceAsync(configuration);
// Obter a coleção
var collection = realm.GetCollection<Users>("users");
// Exemplo de operações com a coleção
Debug.Log(collection);
/*
realm.Write(() =>
{
collection.Add(new MyModel { Name = "Example" });
});
// Consulta de dados
var result = collection.Where(o => o.Name == "Example");
foreach (var item in result)
{
Debug.Log("Item: " + item.Name);
}
*/
}
}
public class Users : RealmObject
{
[PrimaryKey]
public string _id { get; set; }
public int Advertencias { get; set; }
public int ApostarParaResgato { get; set; }
}
yeah so just use realm
So u say i can still use partitionSync right?
how did u made the connection?
was going to look into the flexible mode but haven't gotten around to it
i thought i didnt needed the email and password
only?
pretty much thats why the SDK is there
thx imma look it up 🙏
also you want device Sync if you have an actual mongodb Atlas to sync to instead of using realm only
using Realm i cant connect with Atlas?
thats what the Device Sync feature is for
Realm was technically a mobile devices db
then got expanded and bought into mongo
now got renamed to atlas sdk though so haven't kept up with that yet
been working on Unity's cloud system :p
anything to do with web i do async yes
I cant connect just using the realm app id
in the MongoDB website it gives this example: ```c#
var app = App.Create("application-id");
var credential = Credentials.Anonymous();
try
{
await app.LogInAsync(credential);
}
catch (Exception ex)
{
Console.WriteLine($"Login failed: {ex.Message}");
}
but Unity is refusing to accept Anonymous or local-userpass credentials
im not sure
yes imma show u
Login failed: InvalidSession: authentication via 'local-userpass' is unsupported
and it says the same thing using anonymous
if you are not sure you probably didn't do it
on the website, in the https://services.cloud.mongodb.com
under Authentication ?
i did it now
should i use API-key?
it worked im logged in but im getting this fat error: ```c#
Connection[1]: Session[1]: Received: ERROR "Invalid schema change (UPLOAD): non-breaking schema change: adding schema for Realm table "Users", schema changes from clients are restricted when developer mode is disabled" (error_code=225, try_again=false, recovery_disabled=false)
imma try enable dev mode
yup
also dealing with scehem/breaking changes starts becoming a pain in the ass
make sure you research that
thx imma do that
i enabled dev mode but still getting the same error.
I think i know the problem, tell me something.
How does the app know which user to connect in the database? Because my database has no reference to unity ids.
unity ids?
no, i meant the database documents
_id
2024-05-02 19:58:26.976 Error: Connection[1]: Session[1]: Failed to integrate downloaded changesets: Failed to transform received changeset: Schema mismatch: 'user' has primary key '_id', which is nullable on one side, but not the other
yes the schemas have to match
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
so on this class ID is not nullable but apparently is on the schema
you dont know how to make it nullable where did you get this class from?
from MongoDB website
Atlas Device SDK
imma change it, i was only trying to connect and test it before.
alright well somewhere then you mistmatched the nullable
bet
do u know what is happening here?
should be fine if the class is partial, its been a while since I touched this
make sure it was saved properly
what the code?
yeah the class
i got auto-save 😦
The only way it works is if i use RealmObject instead of IRealmObject
normally interfaces force you to implement methods inside
but the partial class should be what makes it so you don't have to do it in this object
var items = _realm.All<users>();
Debug.Log(items); //Realms.RealmResults`1[users]
im getting this, but i have two documents. Cant figure it out. 😦
how can i check that?
try inserting document then check online ?
0 Sync Sessions, does that mean its not working?
https://www.mongodb.com/docs/atlas/device-sdks/studio/
you can use this to check the local version
you'd have to investigate the logs
it turns to 1 if i play in unity
so it should be working... right? Im installing the Realm like u sad.
I downloaded the realm-dotnet-12.1.0 and the Realm Studio. But it gives me this messages when i try login.
Im sure im using the right APP-ID and API-Key
And using _realm.All<users>().Count(); I get 0
I saw on internet peaple saying that there is a problem with IRealmObject and that its possible to use RealmObject
I'm not sure . Like I said I've been since using the Unity built in database solution
all these are new errors to me
hey @worldly fox I have been trying different stuff.
Realm is working but i think its only locally. I can create and find objects from Realm but nothing on the MongoDB Clound is detected or changed.
Its only working on my PC i think. How can i change it?
niceee!
I see you ended up going with using the new flexible mode instead of partition