Is there any MongoDB handler for find event? - mongodb

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 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.

Related

Automated functions in Mongo DB

I was wondering if there is something like a script that I can write on the MongoDB side that would do something like delete an item in a list if it is older than a week old etc.
I want to have the DB do this check every day. Are there some kind of automated functions that I can setup on the DB to do this?
I could just write a few small methods to do it on the userside myself, but I remember my old SQL DB having this feature. Any help would be appreciated. Thanks,
If you are using Self-Managed MongoDB, The answer is NO.
Like SQL, MongoDB doesn't support scheduled transactions. However you can run the scheduled jobs in your programming language and perform the operations. For example, https://thecodebarbarian.com/node.js-task-scheduling-with-agenda-and-mongodb
If you are using MongoDB Atlas, Then you need to check this https://docs.mongodb.com/realm/triggers/scheduled-triggers/
Then you might want to check out the MongoDB TTL feature :
https://docs.mongodb.com/manual/tutorial/expire-data/
It won't run every day like a script, but it will automatically remove data after some time.
Hope it can help !

MongoDB in Luigi Python

I would like to know if there is a way to output to a MongoDB in Luigi. I see in the documentation they support files (local FS, HDFS), S3, PostgreSQL but not MongoDB. If not, could someone explain me why not? Maybe it is a bad idea to have it? I would like to store the data in a database because then I can explore it by querying it. However I am using mongodb and I would not like to install another database. I do not need a relational database as I am using the database only to store and query ( NoSql ) without relationships, so the best option is mongodb.
Basically I need a task to read the data and save it in the database. Then the next task take this output and process the data.
Any recommendation, suggestion or clarification is more than welcome. Thanks!
You can try using mortar-luigi.
Check out this link for MongoDB tasks and this example.

How to clone a mongodb collection programmatically through Mongo Java driver of Spring Data MongoDB?

I want to clone a collection to a backup collection, before processing all the entries in it through my Spring controller.
On searching, I came to know about various ways to do so through terminal. There is also a possibility to use executeCommand menthod to directly execute mongodb commands (copyTo command in my case). But again, I could not find a way to do so.
Could somebody please provide me any pointers on this?
you can setup JMX support to your project: http://static.springsource.org/spring-data/data-document/docs/current/reference/html/ , see "Chapter 10. JMX support" section, you will be able to get an administrative MBean, MongoAdmin which will let you perform administrative operations such as drop or create a database, and execute one of your solution candidates, like execute mongodump(http://docs.mongodb.org/manual/reference/mongodump/#cmdoption-mongodump--collection) and mongorestore(http://docs.mongodb.org/manual/reference/mongorestore/#cmdoption-mongorestore--collection) for a simgle collection, during restoration you can indicate the new collection name.
Regards,
Moacy

MongoDB query database for time

Is there a way to query mongodb in such a way that I can retrieve the time?
I often do a check where I check the time the mongodb server is running on before putting data on. I need to know the time on the db server from the point of view of a client.
I'm using the C# .NET wrapper, but if there is a query that can do this on any platform that would be nice too. How would would I get the db time?
I know there are obviously other ways to do this, by synchronizing times. But I need to use this option so there can be no tampering with the local time
db.hostInfo() returns an object where system.currentTime is the current time on the server's host.
I'm not sure what you mean by "from the point of view of a client". But, this might help:
>> db.serverStatus()
returns a big object, which includes the time. Apparently (haven't tested this), for the java driver you can get this with Db.command("serverStatus"), so I would imagine something similar works in C#.
References:
Mongo docs for serverStatus
An answered question about serverStatus in Java

Do you know a way to clean-up heroku/mongohq database?

I'm looking for a way to reset a mongodb deploied on heroku/mongohq, something like
# heroku rake db:reset
I know that's possible to directly login mongohq and drop it, but I'd like a quick command line.
Thanks in advance
Luca
In your title you say "clean up", in your description you say "reset". You also use the word "drop" as if you want to drop a database.
Generally speaking, you don't want to "reset" MongoDB unless there's some server issue.
You generally don't want MongoDB to "running dirty", especially in such a way that it needs to be "cleaned up".
Generally, dropping a database is either an Admin task or a task associated with some test script you are running
rake is a build tool and these are all functions of DB administration.
Would you be able to be more specific about what you're trying to do?
Alright, so I found some more details. It looks like rake:reset does the following:
:reset => ['db:drop', 'db:create', 'db:schema:load']
So, it does a drop, a create and a schema load. These are all Rails-specific tasks and they're all tied to some specific features of SQL databases.
In general, MongoDB doesn't have a schema, so there's normally no need for db:create and db:schema:load. So basically you're just doing a db:drop (and maybe some ensureIndex commands)?
I'm looking at the rest of these rake tasks, and many of them don't really apply to typical MongoDB use cases. If you really want this functionality, you'll probably have to write some of this for yourself.