Loopback with meteor - node.js

we have a database connected to meteor and loopback services each one edits in the same collection in database.
I found that meteor have to create the model in a way and this link in loopback https://loopback.io/doc/en/lb2/MongoDB-connector.html
includes only connecting to database and create model not to connect already with a collection in database so anyone have an idea how to design and connect the two services with same collection to edit ? or they detect automatically the collections once I connect the datasource?

Yes, this should already work. Meteor uses OPLog tailing to detect changes to the database and it doesn't have any opinion on how the documents in the collection should look like. It will create _ids that are strings rather than ObjectIds, but it can work with either. So as long as the other services doesn't mind the string _ids you should be fine.

Related

use custom mongoDB server instead of mongolab

Today i started migrating from firebase to mongoDB,
I used this tutorial and its all up and running http://thejackalofjavascript.com/re-architecting-a-firebase-app-in-node/
When checking the code i see there is a mongolab link connected to the code,
mongodb://admin:admin123#ds061620.mongolab.com:61620/testsync
My question is: can i easily setup my own local database to use instead of this? and what packages i would need to do this?
The main reason for switching to mongo instead of firebase is the pricing, please take this into account.
Yes, of course you can.
First, install mongodb locally, to do that, follow the instructions for the distribution you're working on.
Then, make sure your mongodb service is running.
After that, on your database connection script, change the connection parameters.
I guess that you have something like this on your .js file:
mongodb://admin:admin123#ds061620.mongolab.com:61620/testsync
Just to make a connection test, try to change it to:
mongo://localhost/test
After a successful connection, you can start to manage your database as you want.
As additional information, you don't have to specify user, password and a different port than the mongo's default, because you're using your local configuration, if you want to do so, you have to configure your mongodb server to make it work that way.
I'm working with mongoose ORM to manage a local database, and here's my connection function working.
Mongoose connection to local database
Hope this helps you.

Mongoose Schema.post across network

I have two Node.js applications each running Mongoose on a different machine. There is a single MongoDB database running on the first, and the second connects to it and adds documents periodically. I'm trying to add a hook to the creation of these documents so the server running the database is aware that other server has added data. I tried using the Schema.post() method, but it doesn't seem to work since there are two separate instances of Mongoose. Is this true or am I just implementing it incorrectly? I can get the hook to fire if the document is created on the same server, but not the other.
So my thought is to add the hook to MongoDB directly, instead of Mongoose, but I'm not sure how to go about doing that. Am I on the right track?
That is true, Schema.post() only work in the same process. You either need to use a library that tails MongoDB's oplog (like mongo-oplog), implement it yourself using a message queue (or pub/sub) that all instances are connected to (like Redis, RabbitMQ, etc) or use a database that supports this natively. PostgreSQL supports this with its NOTIFY feature for example.

How do I sync a mongolab database to a local mongodb database using nodejs?

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!

MongoDB, mongoosejs - using multiple DBs?

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?

is it safe switching db on mongoose?

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.

Resources