I have nodejs application with express. I store my session in mongodb. But also I store application data that I store in the same db. Should I create another mongodb database for a sessions?
You can use the same database, but have different collections (a collection in MongoDB is somehow similar with what MySQL calls table). That would be ok too.
Related
I want to add data to different databases of mongodb at runtime depending on the request. How can i connect to multiple databases in nodejs at runtime?
For MongoDB, IN NodeJS, you cannot connect to multiple databases at once,
But I suppose you want to add data to different databases, for that you do like this article :-
https://medium.com/#rajamanii/connecting-multiple-database-in-nodejs-with-mongodb-and-mongoose-d88574fcd5a3
guys. I have a local database on mongodb. I also have an identical db on mongolab. In the mongolab db, I append document/entries regularly. What I want to do is to sync these changes on my local mongodb collection. I'm currently thinking of doing a periodic query on the mongolab collection to see if the document count increases and if it does, I would know that there are new documents to account for.
Is there a more efficient way to do this? Thanks!
What is the benefit of using Redis as socket.io memory store, does it need additional resources. I'm using MongoDB as the database, can i use MongoDB as memory store for Socket.io, or do i replace MongoDB with Redis as database? What would be more efficient for building a real-time web app and providing maximum concurrent connections?
can i use MongoDB as memory store for Socket.io
Yes, you can try mong.socket.io
do i replace MongoDB with Redis as database?
Redis and MongoDB are different kind of databases, while mongodb is document oriented redis is key/value oriented (we can even say that redis is a data-structure server).
What would be more efficient for building a real-time web app and providing maximum concurrent connections?
Redis will be definitely faster than mongo on that matter, it supports pub/sub out of the box (while mong.socket.io uses a collection to simulate pub/sub) but you must know that all your data stored in redis must live in memory (here the only data that will be stored in redis will be additionnal socket.io informations).
My backend is NodeJS and uses 2 DBs (MongoDB) with mongoose. One of them has a Users collection and the other db is used for a messaging service that uses user ids.
Does .populate() work across DBs? If so, how is that done?
Would mirroring the users in both DB, where the messaging one would only have a subset of fields for the users, be an a good option?
Also, is it worth having 2 DBs worth it for scalability?
in my application I have a default database and other database I have to connect to in function of client's requests , since with mongoose in node as far as I understood: there is a pool of connections application wide, if I change database, it is changed for all the subsequent requests, I think it could cause some problems, what is the best way to switch Database with mongoose?
Mongoose 3.7.1 (unstable) supports switching databases.
Otherwise you'll need to create separate connection instances for each database.