Querying Morphia by Id

后端 未结 3 512
傲寒
傲寒 2021-01-13 11:09

I am using Morphia, the Pojo mapper for MongoDB, and I find difficult a task that in my view should be very simple: getting an object by id. I am able to find all the object

3条回答
  •  礼貌的吻别
    2021-01-13 12:02

    Datastore ds = morphia.createDatastore("testDB");
    String hotelId = "516d41150364a6a6697136c0"; // the ID of the hotel we want to load
    ObjectId objectId = new ObjectId(hotelId);
    // and then map it to our Hotel object
    Hotel hotel = ds.get(Hotel.class, objectId);
    

提交回复
热议问题