Connect to mongodb using Morphia in Java


Karan

I'm trying to connect to MongoDb using Morphia in Java. I went through some tutorials and some questions asked in stackoverflow. They both use "createDatastore", which is deprecated. There are two ways to create a datastore, both are deprecated. What is the alternative to this method. The way I use it is as follows

    Morphia morphia = new Morphia();
    morphia.mapPackage("org.mongodb.morphia");
    final Datastore datastore = morphia.createDatastore(mongoClient, mapper, "equity");
    TestData testData = new TestData ();
    testData.setAvg(new BigDecimal("500.02"));
    testData.setDate(Date.valueOf("2021-08-20"));

    datastore.save(testData );

Edit 1: enter image description here

absolute

It depends on the version you are using , but with version 2.2 you would connect something like this:

final Datastore datastore = Morphia.createDatastore(mongoClient, "equity");
datastore.getMapper().mapPackage("org.mongodb.morphia");

Related


Persist and retrieve maps using Morphia and Mongodb

Ron Tuffin: I want to be able to persist and retrieve maps etc from MongoDB collections. I am using Java to access MongoDB through Morphia. The example I use below is a collection with documents detailing various car owners. In this example, the number of vehi

Persist and retrieve maps using Morphia and Mongodb

Ron Tuffin: I want to be able to persist and retrieve maps etc from MongoDB collections. I am using Java to access MongoDB through Morphia. The example I use below is a collection with documents detailing various car owners. In this example, the number of vehi

How to insert a list of objects into mongodb using morphia?

Swapnier 1988 Hi I am trying to insert a list of objects List<User> usrListto mongodb using mongodb morphia . I have searched but didn't get any how-to. please help. Here is my user pojo class. @Entity("user") public class User { @Id ObjectId id;

Persist and retrieve maps using Morphia and Mongodb

Ron Tuffin: I want to be able to persist and retrieve maps etc from MongoDB collections. I am using Java to access MongoDB through Morphia. The example I use below is a collection with documents detailing various car owners. In this example, the number of vehi

How to insert a list of objects into mongodb using morphia?

Swapnier 1988 Hi I am trying to insert a list of objects List<User> usrListto mongodb using mongodb morphia . I have searched but didn't get any how-to. please help. Here is my user pojo class. @Entity("user") public class User { @Id ObjectId id;

Java mongodb (morphia) ensure unique documents

Chris Turner I have a task that runs every n seconds to scan the filesystem for new files and store them into a collection. I'm not sure the best way to make sure I don't have the same file appearing twice in the database. Currently I'm using the absolute path

Case insensitive sorting using Morphia (Java)

Daniel I have a Java project and a MongoDB database. I use Morphia to query data. I need to sort this data based on a field that may start with a lowercase or uppercase letter (or even numbers or symbols, but that's not relevant here). My problem is that Morph

Unable to connect with MongoDB using Java driver on Heroku

ZW I am building a web application with Java and MongoDB on Heroku. I learned this project from here . I've been trying hard for two days. I use 3.2.2 mongo-java-driverand3.5.1 maven-compiler-plugin This is in my Mainclass: public static void main(String[] arg

How to connect client to mongodb using java plugin?

Itaied I have a mongo database instance and I want all clients to connect to it. I write in mongo shell db.currentOp(true) I got all the clients and their properties. How to extract data in Java? I tried something like this, but it didn't work: mongoclient.g

Connect MongoDB with Android Application using Java

Gotham Gopalakrishnan I'm currently developing an Android application that consumes real-time data from a remote server in JSON format. So I plan to use MongoDB as a remote server. However, the problem is that I need to return data when accessing a specific UR

How to connect client to mongodb using java plugin?

Itaied I have a mongo database instance and I want all clients to connect to it. In the mongo shell, I write db.currentOp(true) I got all the clients and their properties. How to extract data in Java? I've tried something like this, but it didn't work: mongo

How to connect client to mongodb using java plugin?

Itaied I have a mongo database instance and I want all clients to connect to it. In the mongo shell, I write db.currentOp(true) I got all the clients and their properties. How to extract data in Java? I've tried something like this, but it didn't work: mongo

Connect to MongoDb using SSL from JAVA application

Gurkha: I have a running MongoDbinstance (single instance) SSLenabled. I can connect using the RoboMongolocation on the following tabs SSL: CA File : /path to my certificate/testCA.pem PEM certificate/key: /path to my key/testKey.pem which connects successfu

Unable to connect with MongoDB using Java driver on Heroku

ZW I am building a web application with Java and MongoDB on Heroku. I learned this project from here . I've been trying hard for two days. I use 3.2.2 mongo-java-driverand3.5.1 maven-compiler-plugin This is in my Mainclass: public static void main(String[] arg

Connect MongoDB with Android Application using Java

Gotham Gopalakrishnan I'm currently developing an android application that consumes live data from a remote server in JSON format. So I plan to use MongoDB as a remote server. However, the problem is that I need to return data when accessing a specific URI (eg

How to connect client to mongodb using java plugin?

Itaied I have a mongo database instance and I want all clients to connect to it. In the mongo shell, I write db.currentOp(true) I got all the clients and their properties. How to extract data in Java? I've tried something like this, but it didn't work: mongo

How to create composite unique index in Morphia/MongoDB Java?

rain ear Suppose I have a MongoDB entity that looks like this: @Entity(value = "car") public class Car { public String manufacturer; public String model; public String year; public Double price; } I want to add an index so that the pair manufactur

How to create composite unique index in Morphia/MongoDB Java?

rain ear Suppose I have a MongoDB entity that looks like this: @Entity(value = "car") public class Car { public String manufacturer; public String model; public String year; public Double price; } I want to add an index so that the pair manufactur

How to create composite unique index in Morphia/MongoDB Java?

rain ear Suppose I have a MongoDB entity that looks like this: @Entity(value = "car") public class Car { public String manufacturer; public String model; public String year; public Double price; } I want to add an index so that the pair manufactur

References in MongoDB/Morphia

User 3579222 I found this article discussing whether citations between documents should be established. I want to annotate my Javaclass so I can JSONcreate a reference in the documentation : { "id": "3", "bs": [ { "name": "abc"

Mongodb Morphia gathering

Jimmy I'm having problems creating aggregates in Morphia, the documentation is really unclear. Here is the original query: db.collection('events').aggregate([ { $match: { "identifier": { $in: [ userId1, userId2 ] },

Mongodb Morphia compound query

ElMariachi25 I want to execute this query in Java with the Morphia driver for Monphi DB, this is how (and how it works) for me in the mongo shell db.prova.find({“ username”:“ prova”,“ roles”:“ user”}) escape You should check out the documentation . There are m

References in MongoDB/Morphia

User 3579222 I found this article discussing whether citations between documents should be established. I want to annotate my Javaclass so I can JSONcreate a reference in the documentation : { "id": "3", "bs": [ { "name": "abc"

MongoDB Morphia says deprecated

Fivetech My application works fine. I use this official reference to study morphine: http://mongodb.github.io/morphia/1.2/getting-started/quick-tour/ In Employee class: @Indexes( @Index(value = "salary", fields = @Field("salary")) ) It says value is depr