MongoRepository set timeout - spring-data

Hey Fellow developers,
I want to kill DB operations that last over a minute, some kind of timeout, not only for the backend code but to kill the DB process.
I'm using Atlas DB (mongo 4+) and the backend is written in Java, Spring, and I'm using MongoRepository and extending it with my own interface.
Any idea if this is possible?
Need to kill the MongoDB task, some kind of timeout over the query.

I'm looking currently for possible options and found out that it's possible to configure maxTime for the query. So it should be killed after the timeout defined.

Related

Getting an error "use of closed network connection"

My application stack consist of Golang for backend programming & MongoDB Atlas Free Tier for database. I am trying to trigger events from Stripe CLI and my GoLang programs updates a bunch of tables in MongoDB Atlas based on certain validations. This seems to work fine for the most part. But at certain times in the process, I am facing the below error while updating data into Mongo Collections.
connection(xxxxx-shard-00-02.ka3rc.mongodb.net:xxx[-15])
incomplete read of message header: read tcp
xxx.xxx.x.xx:xxxxx->xx.xx.xxx.xxx:xxxxx: use of closed network connection
I am trying the use the same mongo client that i opened when control enters my Go program to execute all queries within the application.
Do anyone know the reason why we would face this error? Could this be due to Mongo Atlas restricting the number of requests per minute for free tier? This issue happens so randomly and i am not able to determine any pattern when this occurs.
From the go driver client options page:
https://pkg.go.dev/go.mongodb.org/mongo-driver#v1.8.0/mongo/options#ClientOptions
Most of timers are 0 by default :
( ConnectTimeout , MaxConnIdleTime , SocketTimeout )
This mean that in some cases server can close the connection , but the application driver to still not be aware , so it is recommended those timeouts from the client side to be set explicitly during connection init phase.

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 !

Is there any MongoDB handler for find event?

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.

Job scheduling in MongoDB

The project in which I am working requires synchronization of data between MongoDB and SQL Server, so what is the best way for it? This synchronization should be handled by MongoDB side; does MongoDB support job scheduling?
I am new in MongoDB and I want to know few things about it. I know it is not an RDBMS but in case it is possible, then how?
Like we can write program in Oracle can we write in MongoDB. I mean directly in MongoDB, if no then which client side language can used?
As #Vasanth said, MongoDB has no native job management.
As to which client side language: well that's entirely upto you.
You can always get get a prebuilt replicator like: http://code.google.com/p/tungsten-replicator/ that might do the job for you.
As further reference, this question maybe of help to you: https://softwareengineering.stackexchange.com/questions/125980/can-sql-server-and-mongo-be-used-together

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