I’m unable to query my database Item
in order to retrieve an array of objects.
when I run this function const items = await (await realm).objects("Item");
I get this in return:
First, you don’t need the await
s in order to retrieve your object. const items = realm.object("Item")
is enough.
The object items
is a managed collection i.e., it is not a plain JavaScript array. You can still do items[0]
to get the first object, etc.
The benefit of a managed collection is that it is live and lazy loaded. You can read more about it in the documentation.
Is it possible to export a single mongo instance and use it other files?
Yes, you can use items
elsewhere. Actually, items
is a live object.
What i mean is i’m trying to export useRealm
and use it other files:
import Realm from "realm";
import { getRealmApp } from "../functions/realmConfig";
import { ItemSchema } from "./itemSchema";
const app = getRealmApp();
const user: any = Realm.User;
const useConfig = {
schema: [ItemSchema], //other schema will be added in the future
sync: {
user: user.apiKeys,
partitionValue: user.name,
},
};
export const useRealm = Realm.open({
schema: [ItemSchema],
sync: {
user: user.prototype,
partitionValue: app.currentUser?.id!,
error: (e) => {
console.log(e);
},
},
});
@Tony_Ngomana see my response in your other thread.
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.