0

I want to know is there any handler or trigger kind of functionality exist in MongoDB which can help me to run my mongo command on find query?

Basically, I want to run a specific set of Mongo queries on find query. You can say a listener on find query to run other mongo commands.

Other than that is there anything like create a view from a remote database, I know MongoDB provides creating a view from the same database but I want from the remote database?

I do not want any application level solution like any third party module or watcher script, I want something which is within the MongoDB itself like inbuilt function or any event handling.

I have tried auditing but, it only records the operation and all, does not provide any handler through which I can run my mongo commands like Oracle providing in Fine-grained auditing.

Any help related to this is appreciable, Thanks in advance.

1

I want to know is there any handler or trigger kind of functionality exist in MongoDB which can help me to run my mongo command on find query?

Basically, I want to run a specific set of Mongo queries on find query. You can say a listener on find query to run other mongo commands.

As at MongoDB 3.4, there is no server-side functionality for query listeners or triggers. There are some open feature suggestions for triggers in the MongoDB Jira issue tracker, but these all appear to be associated with operations that update data (insert, update, delete) rather than find queries.

Other than that is there anything like create a view from a remote database, I know MongoDB provides creating a view from the same database but I want from the remote database?

As at MongoDB 3.4, there is no in-built feature for creating views from remote databases or deployments.

I do not want any application level solution like any third party module or watcher script, I want something which is within the MongoDB itself like inbuilt function or any event handling.

Although you've excluded third party solutions, there are currently no built-in features or feature requests matching your description. You could certainly raise one or more feature requests with a description of the use cases, but I think both of these approaches sound more suitable for implementing in an application layer with your business logic rather than embedding that into a distributed database.

As a more general solution to enable the use cases you've described, I suggest putting an API layer between your applications and your MongoDB deployment. The API layer could intercept queries and perform the desired actions based on your use case, and is an option available to you without any dependencies on MongoDB server features.

I have tried auditing but, it only records the operation and all, does not provide any handler through which I can run my mongo commands like Oracle providing in Fine-grained auditing.

The auditing feature (which is part of MongoDB Enterprise) is only intended to record configured operations of interest. If you want to do special processing based on queries you will have to implement this in your own application code.

| improve this answer | |
  • Thank you very much @Stennie, It makes sense to me. Is there anything like to create a view from store function of MongoDB. Actually, i did not try that yet, so asking you here. – gaurav nayak Apr 3 '17 at 13:06
  • Views in MongoDB 3.4 return read-only results of an aggregation pipeline as applied to a source collection or view. This includes features such as data manipulation, variables, conditional logic, and looking up related docs from collections in the same database. The expressiveness of views is limited to the aggregation pipeline's stages and expressions, which are increasingly rich but do not go as far as accessing third party libraries or arbitrary functions. – Stennie Apr 3 '17 at 22:22
  • @gauravnayak In terms of mindset for using MongoDB: you are generally best modelling data to support your common use cases and limiting the amount of processing work you offload to the database server. The Data Models section of the MongoDB manual provides an introduction to data model concepts and some common patterns. If you want to learn MongoDB in more depth, there are some very helpful (and free) online courses available via MongoDB University. – Stennie Apr 3 '17 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.