Mongolab: search for multiple documents by _id - mlab

I use MongoLab as a backend store for an angular app. I have a collection with documents and I have an array of _ids. Is it possible to retrieve all documents from the collection that have an _id value that is present in the array?
I am looking for a REST call since I have a Angular app that requests data from the MongoLab REST api
Thanks!
Marc

Sounds like you're looking for the $in operator: http://docs.mongodb.org/manual/reference/operator/query/in/. If you need any additional assistance crafting the query feel free to email us at support AT mongolab dot com.
Cheers!

Related

Using aggregation pipeline on MongoDB atlas trough API

I'm using MongoDB atlas on my flutter app, the data is going to be used through an API, I can now add documents and basic stuff, but I'm not really familiar with the aggregation pipeline, but I need to retrieve the number of all documents in my database. This is how aggregation pipeline should look:
Can someone tell me how can I retrieve the number of all documents with the pipeline using API. I've been experimenting but I'm really not familiar with the aggregation pipeline.
Thank you in advance!

How to connect to a collection in mongodb

I want to use the collections as DBs!.. make a connection from nodejs where you can use a collection as a normal database.??
The purpose of this is that I'm going to create two totally different apps, with different collections and documents, but there are data that I need to relate between the two apps. And if the two apps are using the same database, it would be much easier for me.
Well.. MongoDB doesnt do that, what can you do is something like give a prefix name to your collections, "projectA_Users , projectB_Users" and to relate data use the $lookup Aggregate operator to get your relationship. I see something like that on FireBase that you can create a collection inside a document and use find, update, remove on it (here)

What is the difference between find({}, {sort: ...}) and find().sort(...)?

In MongoDB documentation, when I search for sort, it direct me to the cursor.sort() page. (btw the documentation doesn't specify what is returned out of this method.). So I used it in my meteor script Collection.find().sort('date':1), but got complained that find().sort is not a function. (I thought find() does returns a cursor, isn't it?)
So I did some further search, and found some tutorials tell me to use find({}, {sort: ...}).
So what is the difference between these two methods?
Using find({}, sort... Asks Mongo to do the sorting, and this is the most efficient way because the database server can optimise a sort if a field is indexed.
Meteor doesn't provide the full Mongo api, because mini Mongo in the browser does have all the features and they want to provide a consistent api in both client and server.
I haven't checked it but I think if you add a fetch () in between the find and the sort it will work because fetch will return an array which is sortable
In the Meteor framework, some things you need to do the Meteor way!
Just use Collection.find as specified in the Meteor Docs, and pass a Sort Specifier.
What is the difference between the two?
One has been wrapped by Meteor, and works inside the framework, the other one doesn't!
I don't believe you will see any performance difference between 'the Meteor api' from in the framework, or 'the standard MongoDB api' from (non meteor) nodejs.

Is it okay to use MongoDB _id outside of MongoDB (Mongoose) context?

I am using MongoDB with Mongoose.
I was wondering, if it is bad practice to use MongoDB IDs outside of MongoDB context. Since a lot of my objects need an ID to be identified, I was wondering if I just could use the IDs MongoDB gives them anyway or is that bad practice?
Best regards
What I understand from your question is that if have a document from Mongodb that becomes an object in your application. To identify this object across the application, you want to use this _id so that changes to this object can be tracked easily. If this is the case, you should be using it happily. Because the ObjectId's of Mongodb are unique.
Infact, I do use this _id in my android application. example code here
studentUniqueId.setText(dataModelItem.get_Id());
where studentUniqueId is a hidden field in my android application.

"Pointers" in MongoDB?

In the project I am currently working on, it seems to make more sense efficiency wise if I create a nested document that contains a list of "pointers" to information stored in other collections. That way this nested document can be easily used to retrieve a list of relevant information. The question is, how to do this? Is there a way to store locations of other information in a field in MongoDB? If not, could anyone suggest a scheme that is equally or more efficient? Thanks very much!
There is no GOOD way to do this. If this is what you're looking for, you should be using a relational database.
But if you HAVE to go by this route then, why not store ID's in a document, and then link those ID's to documents in the other collection.
Unfortunately, this would require you to do 2 separate queries, as Mongo does not support compound queries that span documents.