im learning quarkus and mongo panache, and cant find a way to implement java code using watch and change stream but i cant find a way to make it work with mongo panache reactive actually im using a CRON schreduled but i dont want to send a find every 1 hour, reading this document cant find the way to make it work in a reactive mongodb panache with quarkus.
MongoCollection<Grade> grades = db.getCollection("grades", Grade.class);
ChangeStreamIterable<Grade> changeStream = grades.watch();
changeStream.forEach((Consumer<ChangeStreamDocument<Grade>>) System.out::println);
This is my repository
#ApplicationScoped
#RegisterForReflection
public class BrandRepository implements ReactivePanacheMongoRepositoryBase<Brands, Integer> {}
Documentacion Mongo
Thank You
Related
I want to implement autocomplete on a stand-alone instance of MongoDB using C#.
I saw MongoDB has Autocomplete search on MongoDB Atlas but I want to have it on our stand-alone instance.
I also know that we can implement it using Regex like below.
var filter = builder.Regex(x => x.Name, new BsonRegularExpression(new Regex($"^{request.Term}", RegexOptions.IgnoreCase)));
Is there any more efficient way to implement it?
I want to write to MongoDB with Spring Integration and Project Reactor. My needed command is a merge operation, so I started that with the following snippet:
MergeOperation mergeOperation = Aggregation.merge()
.intoCollection("someCollection")
.on("_id")
.whenMatched(MergeOperation.WhenDocumentsMatch.mergeDocuments())
.whenNotMatched(MergeOperation.WhenDocumentsDontMatch.discardDocument())
.build();
#Bean
public IntegrationFlow dataPipeline() {
return IntegrationFlows.from(somePublisher)
// .handle(-----) - MergeOperation usage syntax
.get();
}
I would like to know what is the recommended way of using the merge command with Reactive Spring Data Mongo, and if its supported and possible with reactive streams. Since I've seen that there's a dedicated class for reactive aggregations, I wonder if the absent of reactive merge operation class means no support for the merge operation with reactive streams. If it is possible, I'd like to get some help with the syntax
I am trying to implement Spring Data Crate API in a project. Following the instructions provided here:
https://crate.io/a/using-sprint-data-crate-with-your-java-rest-application/
Inserts/Updates/FindById methods are covered. My question is how to create custom queries using this API.
Have you looked at our Spring Data adapter?
Declared Queries
It's also possible to use the #Query annotation to define queries:
public interface UserRepository extends CrateRepository<User, String> {
#Query("select * from users")
List<User> getAllUsers();
}
https://github.com/crate/spring-data-crate#declared-queries
please note that the crate java-client is not supported anymore since v0.57 unfortunately.
https://crate.io/docs/clients/java/
This leaves us with the java-jdbc:
https://github.com/crate/crate-sample-apps/blob/master/java/documentation.md
Spring data adapter is using the java-client.
Here is a Spring Boot application that is using JDBC in order to access CrateDB (> v0.57.0) https://github.com/klearchos/crate
And here are the official samples in order to access CreateDB through JDBC (using the Spark framework). https://github.com/crate/crate-sample-apps/tree/master/java
How can I store information about class of object when I save it to Mongo? I'm using Scala and Play.
More details. Lets say, we have Trait User and 2 implementations: Admin and Member. And then we try to save them to one Mongo collection.
class UserDao {
private def collection = ReactiveMongoPlugin.db.collection[JSONCollection]("users")
def save(user:User):Future[User] = {
collection.save(user) //Fail
}
}
And we get error. Because we need Reads and Writes for Trait which are really ugly and complicated things..
Before I've written application in Java and Spring Mongo and there wasn't any problems. Spring automagically add _class field to this bson object, which is stored in Mongo. And after read from this collection spring knows which should create. And in Play there is nothing like that.
Please, help me..
I found information, that this is impossible in play reactive mongo driver and generally in play mongo. So there is only one way- write your own driver or think about different solution.
spring-data-mongodb. How can i dynamically create a database in mongo using spring-data-mongodb library?
I am trying to use Spring-Mongodb-Data module for CRUD operations against Mongo database and going through examples and articles my assumption is that databasename should be pre-defined in spring context xml when defining MongoTemplate bean.
In my case I have an multi-tenant application that will accept requests over http and my application should create the mongodatabase on-the-fly and use the name provided in the input http request to create the database and then load the data into collection in the newly created database.
I am trying to figure out if there is a way to dynamically populate the databasename in MongoTemplate or MongoRepository without having to provide it in spring context.xml?
Please help me.
Thanks
-RK
Have you tried the following instead of going through the pre-defined spring context configuration.
MongoTemplate getMongoTemplate(Mongo mongo, String database) {
return new MongoTemplate(mongo, database);
}