How to use Parse server without MongoDb? - javascript

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 😊

Related

Firebase Auth & MongoDB Database

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 !

Cannot create database with pouchdb in couchdb

while trying to just create a database with pouchDB for couchDB, the following error is thrown:
{"error":"not_found","reason":"Database does not exist."}.
My code to create a test db is as simple as this:
var db = new PouchDB('http://localhost:5984/testdb');
Also, the couchDB server is running and reachable at http://localhost:5984/ and it says:
{"couchdb":"Welcome","version":"2.1.1","features":["scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
I have even enabled CORS for couchDB.
Thanks in advance.
According to the PouchDB API (especially the info block), it doesn't automatically create the database by creating a new PouchDB object.
You need to call an API function of the database in order to create the database.
For example, you could create your PouchDB object and then call db.info() to create the database.

Use JSON File as a Database with Sequelize

I want to use sequalize but not with sqlite , postgres etc. . I want to put my data in JSON file is it possible ? Or is there any library like sequelize which i can use json file as a database ?
Yes! There are quite a few npm packages available which suits your requirement.
Here are few for your reference,
node-json-db - A simple "database" that use JSON file for Node.js project. - https://www.npmjs.com/package/node-json-db
disk-db - A Lightweight Disk based JSON Database with a MongoDB like API - https://www.npmjs.com/package/diskdb
low-db - JSON database for Node and the browser powered by lodash API - https://www.npmjs.com/package/lowdb
Hope this helps!

Frontend accessing MongoDb

For a project, we're going to use the MEAN stack. Having Angularjs as the frontend framework, is there a possibility for the framework directly accessing the data from mongodb (Bypassing node and express)?
Also, is it possible to use meteorjs on the client side? If ever, what are key advantages and can it do direct access to mongodb as well?
Frontend accesing MongoDB is possible, via its HTTP (rest) interface
http://docs.mongodb.org/ecosystem/tools/http-interfaces/
To get the contents of a collection (note the trailing slash):
http://127.0.0.1:28017/databaseName/collectionName/
To add a limit:
http://127.0.0.1:28017/databaseName/collectionName/?limit=-10
To skip:
http://127.0.0.1:28017/databaseName/collectionName/?skip=5
To query for {a : 1}:
http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1
Separate conditions with an &:
http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1&limit=-10
Same as db.$cmd.findOne({listDatabase:1}) on the admin database in the shell:
http://localhost:28017/admin/$cmd/?filter_listDatabases=1&limit=1
To count documents in a collection:
http://host:port/db/$cmd/?filter_count=collection&limit=1
However, I personally discourage this approach. Node/Express can be a simple wrapper for auth/auth before you make any changes to DB.

Why is there separate mongo.Server and mongo.Db in mongodb-native driver?

I am just learning mongodb-native driver for nodejs.
I connect like this.
var mongo=require("mongodb")
var serv=mongo.Server("localhost", 27017)
var dbase=mongo.Db("MyDatabase", serv)
And that works. But if I try to create a new database connection using the same server I get an error.
var dbase2=mongo.Db("MyDatabase2", serv)
"Error: A Server or ReplSet instance cannot be shared across multiple Db instances"
But it works if a make a new server connection first.
var serv2=mongo.Server("localhost", 27017)
var dbase2=mongo.Db("MyDatabase2", serv2)
So my question is why there are 2 connection functions, one for Server and one for Db, when it seems like they must always be used together?
Why doesn't it go like this.
var dbase=mongo.Db("localhost", 27017, "MyDatabase")
I want to make my own function that does this, but I wonder if there is some other reason they are separate.
Thanks.
Here is a link to the solution on the mongo docs, for reference. (seems like the same solution the other poster mentioned)
http://mongodb.github.com/node-mongodb-native/markdown-docs/database.html#sharing-the-connections-over-multiple-dbs
The point of separating the connection to the mongo server, and then the DB is for cases like when you want to connect to a ReplSet server, or other custom params. This way, you have a separate process connecting to a mongodb server.
The database connection call is separate simply because of the case you have here: you dont simply want to connect to a mongo server and a single db, but multiple dbs. This separation of connecting to db and server allows this flexibility.
Another Solution: Use node-mongoskin
Mongoskin does what you want to... it allows connecting to server and db all in one command. Not a solution for mongo-native, but worth considering as an alternative library for your future projects.
var mongo = require('mongoskin');
var db = mongo.db('localhost:27017/testDB');
For what it's worth, you can do what you want to do by using Db#db(), which doesn't seem to appear in the official documentation but is listed in the source code of db.js as being a public API:
/**
* Create a new Db instance sharing the current socket connections.
*
* #param {String} dbName the name of the database we want to use.
* #return {Db} a db instance using the new database.
* #api public
*/
so you could do
var serv=mongo.Server("localhost", 27017);
var dbase=mongo.Db("MyDatabase", serv);
var dbase2=dbase.db("MyDatabase2");
Because these are two separate and distinct actions - you have to connect (or already have a connection) to DB server (computer) in order to query any of the databases on that particular server. You can create distinct database query connections for each of the databases that you will want to use, but at the same time you will be using the same connection to the server.
Most of the time you will NOT want to create a separate server connection for each of the databases (if there are many) because the server usually limits the number of connections.

Categories

Resources