Open takameyer opened 1 year ago
For what it's worth, this is an implementation I did for another app I was working on:
export function useMongoClient() {
const user = useUser();
return useMemo(() => {
return user.mongoClient("mongodb-atlas");
}, [user]);
}
export function useMongoDB(databaseName = config.databaseName) {
const client = useMongoClient();
return useMemo(() => {
return client.db(databaseName);
}, [client, databaseName]);
}
export function useMongoCollection<T extends Realm.Services.MongoDB.Document>(
collectionName: string,
databaseName = config.databaseName
) {
const db = useMongoDB(databaseName);
return useMemo(() => {
return db.collection<T>(collectionName);
}, [db, collectionName]);
}
Problem
If for some reason, a developer wanted direct access to a MongoDB collection, they would have to type the following code to do so:
Solution
This could be abstracted into a single hook:
Under the hood, the hook could register a collection watcher, to update when anything changes.
Alternatives
The above is just a suggestion of what could be possible, but in practice, there could be something better or more ergonomic. A bit of design and research should be done to determine the best path forward.
How important is this improvement for you?
Would be a major improvement
Feature would mainly be used with
Atlas App Services: Auth or Functions etc