Meteor JS database workflow - javascript

As far as I understand, I "publish" named collection server-side, on the client side I "subscribe" to that collection and pass them to Template, where I work only with the data, provided by "published" collection.
Please comment, have I got it right, and what should I do if I have a big collection that I don't want to retreive at once?

That is correct. When using large collections you should add parameters to the publish and/or limit the amount of records being published.
Theres a good explanation about publish/subscribe on Meteorpedia

Related

Auto generate sub database firestore

I have a firestore collection with a bunch of documents, each with plenty subfields. On a web page I need a list of a specific subfields from each document.
Currently I load the the entire database when you load the page and then loop through and get the wanted values. This uses way to many reads to get very little data.
Is there a way to solve this e.g. a autogenerated a collection that contains field from other collection in an array or something.
Many thanks in advance
Auto-creating such a subcollection with just the fields you need is a great way to reduce the bandwidth needed to load the data.
There is nothing built into Firestore to create those derived documents, but it's fairly easy to build something using Cloud Functions. Create a function that responds to a Firestore onWrite trigger, and write the subset of the data to its destination there. It's common to have a separate Cloud Function for each such use-case, and I regularly see projects with 100+ such functions.
I expect we'll also start seeing Firebase Extensions for this type of thing, but right now no-one seems to have built one.

Why mongoose.model() is required to get data from MongoDB?

I want to read data from the mongodb with mongoose, but every time it requires creating a model. Why?
I thought model are just like templates to insert data to MongoDB.
Can anyone describe what exactly mongoose.model() is and how it works?
I tried
const Model = mongoose.model(mongoose.Schima())
Without object in it
And it worked as well!!!
How does mongoose.model get data in background?
Thank you...
Mongoose models are much more than just templates on how to store data in the database: they perform type conversion, provide validation, have pre/post hooks, provide easy methods for population, and much more.
You don't need to use a full model to retrieve data from the database (in fact, you don't even need Mongoose at all), but you'll lose all the additional features.

Where reside the returned records of the mongodb function currentOp()?

exist any way to know if this function collects information from an accesible collection?
For example these registres:
db.currentOp(true).inprog.forEach(function(d){if(d.client)print(d.client, d.connectionId)})
I was looking at the data in the 'oplog.rs' collection but it didn't seem contain what I am looking for.
There's no database collection mentioned in the documentation which means that currentOps are most likely held in an internal MongoDB data structure.
Browsing the github MongoDB repository and the body of currentOp method leads to CurOp C++ class which is simple in-memory stack implementation so there's no persistent storage for current ops.
You can also take a look at system.profile if you're trying to build some sort of diagnostic solution which requires persistent storage.

Firebase database retrieving data from comma seperated list

I want to store the comma separated ids on a child node & how can I filter data as in sql we can use IN clause to fetch data any possibility in firebase to perform this kind of operation in firebase database.
Please suggest any possible solution for this.
Firebase Realtime Database doesn't have the equivalent of SQLs IN clause. It also doesn't have a way to find a substring in a value. So the data model you are looking to use, doesn't allow the use-case you want. As usual with NoSQL databases, the solution is to pick a data model that does allow your use-case..
The most likely cause I know for the structure you describe is to associate the child node with a bunch of categories. If that is your case, read my answer here for a proper data structure: Firebase query if child of child contains a value
This is one of the cases where the new Cloud Firestore database offers better querying support, since it recently added a feature to efficiently test if an array contains a certain value (video). If you're only just getting started with your project, you might want to check if Firestore is a better fit for your use-cases.

Manage relations among users in db

I am creating a mock app with user creation/auth/friend in a node js learning exercise. Having spent my time mostly at the front end of things, I am a n00b as far as DBs are concerned. I want to create a user database where I want to keep track of user profiles and their connections/friends.
Primary objective is to load/store users connections in the database.
Fetch this information and give it to the user most efficiently in least number of queries.
I'd really appreciate some help with a DB structure I should be using that can accomplish this. I am using mongodb and node.
Off the top of my head: I can store the user's connections in an object in the "connections" field. But this will involve making a lot of queries to fetch connections' details like their "about me" information - which I can also store in the same object as well.
Confused. Would really appreciate some pointers.
Take a look at the Mongoose ORM. It has a populate method that grabs foreign documents. Lots of other great stuff too.
You could say
Users.find({}).populate('connections').exec(function(err,users) { ... });
Before popualte the users' array of connections was an array of IDs, after, its an array of user documents.

Categories