Using aggregation pipeline on MongoDB atlas trough API - mongodb

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!

Related

How to store MongoDB aggregation pipelines in the database and run them

I need your help please.
I am using MongoDB aggregation pipelines for displaying a complex report.
Requirements are changing often and product wants our DBA to be able to change quickly the report pipeline.
Even more they want the report to differ based on the client using it, for multitenancy.
We do not have a report builder because e use many different stages that would be hard to express.
Currently I am using Spring Data MongoDB to execute the aggregation pipelines like this:
#Aggregation(pipeline = {...<pipeline JSON>
public AggregationResults<ReportBaseModel> runReport(...);
How could I store the aggregation pipeline in the database as a document so that I can easily read/modify it, and run it with some date period parameters?
Tried Spring Data MongoDB but that means the pipeline is hardcoded into the Java code. I do not want the JSON to be hardcoded.

Can you add an aggregate pipeline to document .save() action?

I use mongoose with mongodb and while updating a document, I first find the document, modify the resultant document object and then do a .save() on the document.
Now I want to add an aggregate pipeline to the save operation so as to control the document response better and so I was wondering if this possible.
I read that the update query can have the pipeline attached to it but does that also apply to the save action?
as far as I am concern in the current version of MongoDB(4.4), the only methods that allow aggregate pipelines are those concerning updateAndModify, and Update. Thus, the limit use that mongoose might bring to this subject. What I would recommend in your case is that you use the aggregation pipeline with Model.findOneAndUpdate(). Here is an example that you might follow: example of aggregate using Model.findOneAndUpdate()
Also you might notice that this is the documentation for MongoDB and not Mongoose. I tend to find it difficult to find useful information for more specific use cases like this one in the docs of Mongoose, therefore the link in MongoDB. It will work the same as with a model from Mongoose so take a shot!

Using MapReduce as a Stage in Mongo DB Aggregation Pipeline

I want to use Mongo DB MapReduce functionality along with Aggregation Query.
The below are the stages which I see could be part of the Aggregation pipeline.
Filter docs for which the user has access based on content in the docs and
passed security context(roles of the user)
(Using $REDACT)
Filter based on one or more criteria (Using MATCH)
Tokenize the words in returned docs based on above filtering and populate a
collection (Using MAPREDUCE) (OR) return the docs inline
Query the populated collection/returned docs inline for words based on user
criteria using like query(REGEX) and return the words along with their
locations
I able to achieve steps 1,2 and 4 in the aggregation pipeline.
I am able to achieve Stage 3, separately by using mapreduce functionality in Mongo DB.
I want to make the mapreduce operation also as a stage in the aggregation pipeline and use it to receive the filtered docs from the earlier steps and pass the processed result to next step.
The mapreduce operation is based on sample map and reduce operation. I intend to use the map , reduce and finalize functions as shared in the below stackoverflow issue.
Implement auto-complete feature using MongoDB search
My query is I do now know if we can have MapReduce operation as part of the Mongo DB aggregation pipeline and if so can we use as inline and pass it to the next stage.
I am using Spring Data Mongo DB to implement the Mongo DB aggregation solution.
If someone has implemented the same please help me on this.

MongoDB aggregation query in RapidMiner

How to do an aggregation query in MongoDB from the RapidMiner using the mongodb plugin? I've tried to google around, unfortunately with no success at all. It has a direct support for criteria and projection (using operator "Read MongoDB"), however I don't see anyhow support for the aggregation. It does have an "Execute MongoDB Command" operator, which might be capable of doing that but I can't find any extensive examples on how to use it. Eventually, if the above mentioned is not possible, do you know any other way how to do the "unwind" over the data in the RapidMiner having the mongodb collection loaded in?
The Execute MongoDB Command Operator is a wrapper for the mongoDB command db.runCommand(). If you want to continue working in RapidMiner, you can expand the collection you get as a result from the Read MongoDB and transform it into an ExampleSet with the JSON to Data Operator.

Mongolab: search for multiple documents by _id

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!