1

I am trying to sort capped collection in descending order.

what I have tried:

    @Tailable
    @Query(sort = "{$natural:-1}")
    Flux<Message> findAllByConversationId(String conversationId);

it gives:

Query failed with error code 2 and error message cannot use tailable option with a sort other than {$natural: 1}'

but when I use this query in robo3t:

db.getCollection('message').find({}).sort({$natural:-1})

it works fine !

any help ?

cchantep
  • 9,118
  • 3
  • 30
  • 41
suliman
  • 334
  • 6
  • 17

1 Answers1

1

Seems like I needed to go with native queries using "ReactiveMongoTemplate"

this code works as I want:

public Flux<StreamMessageDto> streamConversationById(String conversationId) {
    Criteria criteria = Criteria.where("conversationId").is(conversationId);
    Query query = Query.query(criteria);
    query.with(Sort.by(Sort.Direction.DESC, "$natural"));
    reactiveMongoTemplate.find(query, Message.class);
}

for more details refer to this link

suliman
  • 334
  • 6
  • 17