I am starting an app (JS / React) and I'd like to use Firebase Authentication system (because it's powerful), with a MongoDB Database (on MongoDB Atlas -Cloud-) for storing the data ( More efficient than Firestore && I use GraphQL on the backend). I still want to use Firebase auth, because I don't want to dive into the authentication rabbit hole for now...
Firebase generates an id for newly ceated users (sent in tokens), I want then to have a collection 'Users' on Mongo to store data about those users.
Here is my problem : The id generated by firebase auth doesn't fit the id syntax required by MongoDb Atlas, to fit the ObjectId type.
Here is an id generated by Firebase :
zOw5ERvHyucA3fPYlXlaa4SI1D23
and here is the error I get from mongo : 'must be a string of 24 hex characters'. Example of a working id :
5e7d4a383cae9a2218b45a55
I could use Stings as primarykey in Mongo but i'd lose the efficiency of ObjectIds.
For now I added a 'authId' attribute on my users, but I don't think this is optimal.
What do you think ? Any advice ?
Thanks !
Related
I am new in firebase.I created app that connect to database and create new id in it.
const db = firebase.store();
my db variable is not reachable.
There is no product names store() in Firebase.
If you're looking for Firestore (for storing documents with fields and values), use firebase.firestore().
If you're looking for Cloud Storage for Firebase (so for storing unstructured files), use firebase.storage().
I have set the mongoDB profiler on my QA database.
db.setProfilingLevel(1, 100)
And get query result is:
db.getProfilingStatus()
{
"was" : 1,
"slowms" : 100,
"sampleRate" : 0.42
}
When I find the result with:
db.system.profile.find()
0
QA env is working and query is triggered from my Nodejs server.
Also operation is performed on qa database (test_Qa) via nodejs service.
But still I am not able to see any query in system profile.
even if some query took more that 30 secs.
Whatever query is doneon admin database (via mongo client directly) thats getting logged in system profile. (if take more time)
Is profile is applicable for admin database only ? (With above command I don't think so)
Whats going wrong here ?
Thanks for your help in advance.
Before apply the profile you should use that DB. In above case Logs getting added in admin database because admin is default selected.
here I need to apply profile on test_QA db. So before applying all above queries I should use test_QA.
use test_QA;
and then,
db.setProfilingLevel(1, 100);
It will apply profile on db test_QA.
Hope it will help if someone run in same problem.
I have an application where the customer creates a company in UI. For every company, I need to create DB in authentication mode with MongoClient in NodeJS.
Databases can be created on the fly. MongoDB will create a database the first time you store data in it (such as when you create a collection in it). See https://docs.mongodb.com/manual/core/databases-and-collections/ for more details.
When using the MongoDB Node.js driver, you can indicate the name of the database and the collection when storing new data. If the database and collection do not exist, MongoDB will create them for you.
Example:
const result = await client.db("sample_airbnb").collection("listingsAndReviews").insertOne(newListing);
The name of the database is "sample_airbnb" and the name of the collection is "listingAndReviews". If those do not exist when this code is executed, MongoDB will create the database and collection. See https://developer.mongodb.com/quickstart/node-crud-tutorial for more examples.
I am trying to migrate from Firebase Real time Database to Cloud Firestore in order to use "complex" queries among collections but I found some "issues" that I don't know how to solve.
My server uses Express JS and Firebase Admin SDK. I am trying to create a CRUD router for my admin dashboard but I am getting the following error:
"9 FAILED_PRECONDITION: The query requires an index. You can create it here: ...
When I access that URL (...) I get some error I don't have enough permissions... Well, anyway, after some research I understood that "complex" queries requires indexes and they have to be more than one.
This is my current router code so you can see what I want to achieve:
// GET - Get users
router.get('/', async (req: Request, res: Response) => {
...
let ref: any = db.collection('users').orderBy('createdAt');
Object.keys(req.query).forEach(key => {
ref = ref.where(key, '==', req.query[key]);
});
...
});
As you can see when I iterate req.query key I am adding a conditional statement to the query. My idea is to progamatically add custom filters from the client.
According to what I understood from documentation, I should create a complex index type for every document property.
Therefore, what should I do in order to achieve the mentioned idea? Thanks in advance.
Firestore compound queries have some limitations.
One is that to use more than one method, for example "where" and "orderBy", you need to create an index for this query.
So in your case, as your queries are dynamic, for each query you will have to create an index.
My suggestion is that you only use the "where" in your queries and in the other filters use javascript to filter. Or migrate to another database like MongoDB.
This is the link to the Firestore documentation explaining the compound queries: https://firebase.google.com/docs/firestore/query-data/queries?hl=en-us
I only need to use Parse sever cloud functions, How can I run parse server without mongodB
How to use Parse server without MongoDb ?
You cannot run a Parse Server instance without a database. For example, Parse store login session into the database
Two databases available with Parse Server
According to the documentation you have two choices of databases:
Postgres
MongoDb
So if you do not want to use MongoDb you have to use Postgres
Here is the difference between theses two databases
How to switch databases ?
If you want to change your database from a MongoDb to a Postgres, you just have to change the configuration:
var api = new ParseServer({
databaseURI: 'postgres://my.awesome.postgres.uri',
});
Hope my answer help you 😊