Using Mongo Stitch with Firebase Storage? - mongodb

I'm currently developing a solution that lets users create a parent listing whereby they can upload files, assign child listings to that and then search their listings based on data from both the parent and child listings.
As an example, think of it as an inventory database. You create your parent listing for say a product, give it a name and upload some images of it. You then create your child listings which would be the stores that stock your product.
Your search capabilities would allow the user to search the product by free text, but also using parameters from the child listings, for example Price, In Stock, Tags etc.
I've tried to develop a concept using Firebase for this which utilises Auth, Storage and Functions, however due to the search limitations of Firestore, it cannot be done.
MongoDB offers something similar to Firebase' functionality whereby I can use Atlas which gives me all the search capabilities I need using Mongo instead of Firestore. In addition, they also have Stitch which provides the Cloud Function, Trigger and Auth functionality I need.
What they don't offer however is any Storage solution.
Does anyone know a way I can use MongoDB Stitch Auth, alongside Firebase Storage to integrate directly with the UI using the Firebase Storage security rules?
I know I could create a Stitch Function that handles the passing of file from UI to Firebase, however I'd prefer to go direct if possible.

Related

How can I retrieve files from Firebase Storage based on user?

I have made a to-do list app using Firebase Auth and Firestore, and I would like to add an attach image feature, with which you can add images to tasks. I need to use a combination of Auth, Storage and Firestore but I'm not sure how to combine them.
How can I reach data from Firebase Storage using Firestore? Before I got into this, I was imagining it would be something like adding an imageLink field to each task, and then linking to the relevant image in Firebase Storage. Is it something similar? What should I do?
Firestore and Cloud Storage are two different services offered by Firebase. They don't communicate with each other. It's up to you to make the link between the different "entities" stored in this two services.
A very common approach for your Use Case is to first upload the file in Cloud Storage, and then save in a Firestore document, either the path of the file or a signed URL to the file (or both, knowing that with the path you can always generate a signed URL).
Another approach consists in getting a Firestore document ID (automatically generated with the addDoc() or setDoc() methods) and use this ID to rename the file before saving it to Cloud Storage. This way the link between the file and Firestore is clearly materialized and you can very easily link them in your front end. You could also use this approach to put in a given folder all the files linked to one Firestore doc: you name the folder with the Document ID.
A third approach is to use the metadata of the Cloud Storage file to store the ID of a Firestore document. Most of the time this approach is less "handy": You either need to know the path of a file or you need to list all the files in a bucket or folder in order to get the ID of the Firestore docs. But for some specific cases it can be an interesting approach, knowing that nothing prevents you to combine approach #1 or #2 with approach #3, if necessary...

What is the easiest way to fetch data dynamically from a cloud storage to a flutter app

I am looking for a way to fetch data to my flutter app which can be adjusted and modified dynamically after deploying the app. As an example, if I want to change the images of the carousel depending on promotions or launch new books to the digital library. I need an economic option to host the data in cloud storage and fetch it from there.
I have considered firebase as well as google drive, but have yet to find a good guide. being a beginner and having concerns about security I want some expert advice if possible.
*edit-
Seeing many a tutorial I assume there is no better way than linking file URLs from the
Cloud Storage. So to dynamically change those is it possible to refer the URLs to some excel sheet fields to obtain URLs. Those fields can certainly be adjusted then without any hard coding. but the question is how to refer to such a sheet file? *
I also want to segregate the users into paid and free users, I have successfully proceeded with the authentication with firebase but still don't understand(I do have some concepts but don't know where to do that) how to put them in groups and impose limitations on them about accessing the data. any guidance, links and helpful advice will be cordially appreciated.
According to what you are looking for, I highly recommend you to use Firebase Remote Config, which is a cloud tool that allows you to modify your app's functionality and appearance without forcing users to download an update. You define in-app default values that control the functionality and appearance of your app when you use Remote Config. Then, for all app users or for subsets of your user base, you may utilize the Firebase console or the Remote Config backend APIs to modify in-app default values.
Your program can control when updates are applied, and it can check for updates regularly and apply them with minimal performance impact.
Remote Config comes with a client library that takes care of essential functions like fetching parameter values and caching them while still allowing you to manage when new values are active and how they affect the user experience in your app.
Here is a tutorial that uses Flutter and Firebase Remote Config that could also help you.

How do I add MongoDB Realm App Users to Atlas collection?

I'm working on a SwiftUI app that connects to a MongoDB Atlas database (hosted) which is populated and managed by a server. I've created a Realm for my SwiftUI app, and can sucessfully create a user and log-in, but I'm having trouble connecting the created user (found in App Users in the Realm UI) to a user document in my database's User collection. Whats the proper way to do this? Do I need to manually create a user in the collection for any new app users?
#jostell13 - REALM users are not ATLAS DATABASE USERS.
However, this does not mean that REALM users need their own collection for any new app.
When you create a realm app, you specify the ATLAS cluster it is associated with. There are multiple ways to do this - I'll go over two. SDK, Functions
https://docs.mongodb.com/realm/sdk/swift/examples/read-and-write-data/#read---write-data---swift-sdk
https://docs.mongodb.com/realm/sdk/swift/data-types/collections/#collections-are-live
The SDK provides LIVE collections, which is a really awesome capability. If LIVE collections, and things like real-time notifications, live updating objects, lazy-loading objects etc are not a requirement, you could also consider functions.
(Credit to #Jay for bringing up SDK > Functions)
https://docs.mongodb.com/realm/functions/
const plants = context.services.get("mongodb-atlas").db("example").collection("plants");
const plant = await plants.findOne();
return JSON.stringify(plant);
Functions can be called from the REALM app, or you could even create things like HTTPS endpoints so you can interact with functions using simple HTTP requests. https://docs.mongodb.com/realm/endpoints/
The best part about functions is - DEPENDENCIES! You can literally use almost any npm module as a dependency for your functions! (There are some limitations, but this featureset will only be improving in the future)
https://docs.mongodb.com/realm/functions/add-external-dependencies/
While I got a lot of useful info from the responses here, the solution I found was not mentioned.
The correct way to do this is still to do a manual copy of data from the Realm to the database via a triggered function.

Create a database entry for the UID after sign up with firebase and swift

I’m developing an app in swift by using firebase in the back end.
I have successfully created a user by using the standard procedure as stated in the documentation.
My problem comes when I want to add the UID value to the database. I can’t. What I’m doing is getting the UID (userID) from the Auth().user (what I successfully do) and using the following code (I don’t have de computer do it can contain errors but I copy it from the documentation and I’m fact it compiles, the problem is that is does nothing
let ref = Database().database().reference()
self.ref.child(“users”).setValue(userID)
I have tried with the following
Self.ref.child(“users”).child(user.id).setValue(userID)
But it fails due to the fact that users have no children. The issue is that users is a collection and I don’t now if it works in the same way or not.
My intentions is to create the entry in the “users” collection in the database just after singing up a new user. (And to be able to layer erase it)
Thanks!
Firebase has two NoSQL databases:
the Realtime Database, which is the original JSON database.
Cloud Firestore, which is the newer document/collection database.
These two databases are both part of Firebase, but have completely separate APIs.
You speak about collections in your question, which are a Cloud Firestore concept. But your code uses the API of the Realtime Database. If you're looking to write data to Cloud Firestore, you'll want to use the API that is documented here.

firebase queries and swift

I have a string for eg: "My name is John" stored in Firebase.
How would I query firebase so I can find all the posts in Firebase that have "John" ?
I can search for the first term in a string now using:
DataService.dataService.BASE_REF.child("Posts").child(selectedComment.commentKey).queryOrderedByChild("userComment").queryStartingAtValue(comment).queryEndingAtValue(comment+"\u{F8FF}").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
where comment = "My"
I read about using Elastic search with Firebase but wanted to check if there was an easier way in Firebase before I looked at ElasticSearch/Flashlight for Firebase,
Unfortunately, Firebase doesn't support searching thru content like that (in any language SDK). From a Google Groups Post in July '16:
As a company that understands search, we're also a company that
understands using the best tool for the job. For fuzzy matching and
contains, a NoSQL, realtime data store isn't the correct tool--these
queries would be slow and scale poorly. BigQuery or ElasticSearch are
the right tool for providing useful results in a scalable and robust
manner.
Right now, this involves deploying a small node script to sync your
search results with the realtime data, as explained in the article
with the sample Flashlight lib. In the future, it will become more
"effortless" as we add integrations between Firebase and Cloud
products, particularly Cloud Functions and BigQuery interoperability.
BigQuery is, as I understand it, not specifically designed for user-facing search.
Elasticsearch (specifically, the Firebase plugin Flashlight) is a potential solution, but as you alluded to, it's an incredible amount of overhead (deploying/managing or renting an ES cluster, configuring the plugin, etc.). If content search is an important enough part of your app to justify that time/$, you may want to consider solutions beyond Firebase for your database needs, as it's by far one of the service's weakest areas.
In my opinion, you have a few options beyond Flashlight:
Algolia, a Search-as-a-service provider, does offer integration with Firebase, but I've never used it & so can't offer much more than to say that it exists.
Another alternative might be maintaining a collection of documents you want to search on another service, like AWS Cloud Search
Depending on the stage of your project & your needs, consider other Backends-as-a-Service that support more in terms of querying. E.g., GraphQL-as-a-service backends, like Scaphold.io, Graph.cool, and Reindex are all built on SQL databases, and (I believe) all support multiple types of querying.