dmendezg
dmendezg

Reputation: 1928

Return last value query in MongoDB in Spring XD Source module

I would like to be able to create a query/query-expression that I can use in SprinXD MongoDB Source module to return only the last document that has been inserted.

It seems that max-messages-per-poll doesn't do the trick (paginated data with the help of mongo inbound adapter in spring integration)

I know how to do it with agreggation, findOne(), limit(), etc, but I haven't found a way to do it with a query object.

My stream is the following:

mongodb --collectionName=Notifications --fixedRate=10000 --query={'$query':{}},{'$limit':1} | log

But I'm still returning all the documents.

Any help is appreciated.

Thanks, David

Upvotes: 2

Views: 149

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121542

We can't do that just with that simple MongoDB source. It requires only the JSON string in MongoDB query style, but there are no hooks to provide options like limit, skip, sort etc.

So, you must have a transformer processor module in your stream to filter all those undesired records from the find result.

Feel free to raise a JIRA ticket against Spring Integration to improve MongoDbMessageSource to accept any Query object, not only String for simple BasicQuery.

Upvotes: 0

Related Questions