How to get the ObjectId value from MongoDB?
Posted
by
LVarayut
on Stack Overflow
See other posts from Stack Overflow
or by LVarayut
Published on 2014-06-05T08:50:37Z
Indexed on
2014/06/05
9:26 UTC
Read the original article
Hit count: 426
I'm using Jongo
with Play framework 2
, java. I added some data into my MongoDB
.
{"_id" : ObjectId("538dafffbf6b562617252178"), ... }
However, when I fetched the ObjectId
from the database, it gave me like:
de.undercouch.bson4jackson.types.ObjectId@484431ff
instead of 538dafffbf6b562617252178
. I don't quite understand how can I get the ObjectId
value. My class is defined as following:
public class Product {
@JsonProperty("_id")
protected String id;
...
public Product() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
EDIT
In order to fetch the data, I simply use find()
function provided by Jongo
as following:
public static Iterable<Product> findAll(){
return products().find().as(Product.class);
}
© Stack Overflow or respective owner