Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When a domain object is persisted in MongoDB, it is stored as a document with an <a href="http://docs.mongodb.org/manual/reference/object-id/" rel="nofollow">ObjectId</a> as a unique 12 bytes BSON primary key. For example, if you have a domain object <code>Product</code> like</p> <pre><code>import org.bson.types.ObjectId class Product { ObjectId id String name static mapWith = "mongo" } </code></pre> <p>then the persisted entity in MongoDB would look like below if you save with a name as "TestProduct".</p> <pre><code>//db.product.find() in mongodb { "_id" : ObjectId("51bd047c892c8bf0b3a58b21"), "name" : "TestProduct", "version" : 0 } </code></pre> <p>The <code>_id</code> becomes your primary key for that document. To <code>get</code> this document you need the primary key ObjectId. Speaking from a RESTful context, you atleast need the 12 bytes hexcode <code>51bd047c892c8bf0b3a58b21</code> as part of the request.</p> <p>So in the above case, you can fetch that particular document by doing something like</p> <pre><code>Product.get(new ObjectId("51bd047c892c8bf0b3a58b21")) Product.findById(new ObjectId("51bd047c892c8bf0b3a58b21")) </code></pre> <p>Have a look at the <a href="http://api.mongodb.org/java/2.0/org/bson/types/ObjectId.html" rel="nofollow">API for ObjectId</a> which would make clear how to retrieve a document.</p> <p>When you retrieve the document as JSON, then it just shows the ObjectId class with its elements.</p> <pre><code>{ "class": "com.example.Product", "id": { "class": "org.bson.types.ObjectId", "inc": -1280996575, "machine": -1993569296, "new": false, "time": 1371341948000, "timeSecond": 1371341948 }, "name": "TestProduct" } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload