-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Realm React
-
3 - M (<= 1 month)
-
5388
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:
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
function QueryPlants() { // Get currently logged in user const user = useUser(); const getPlantByName = async (name: string) => { // Access linked MongoDB collection const mongodb = user!.mongoClient('mongodb-atlas'); const plants = mongodb.db('example').collection<Plant>('plants'); // Query the collection const response = await plants.findOne({name}); return response; }; // ... }
Solution
This could be abstracted into a single hook:
Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
const plants = useMongoDb({cluster: 'mongodb-atlas', db: 'example', collection: 'plants'});
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