retrieveObject

Collection.retrieveObject(dbApiKey, collectionName, objectId, include [, proj][, token])

Retrieves an object from a specified collection.

Parameters

The method has the following parameters:

Parameter

Description

Required

dbApiKey

Database API key.

Yes.

token

String with user session token or database master key.

No.

collectionName

String with name of collection.

Yes.

objectId

Unique identifier of the object that should be retrieved.

Yes.

include

String parameter indicated should or shouldn’t include referenced object.

No.

proj

JSON projection object that was built in accordance with the documentation of MongoDB query.

No.

Response

A response will include the following fields:

Argument

Description

_id

ID of the object created.

columnX

One or more columns from this object.

_createdAt

Date when the object was created.

_updatedAt

Date when the object was updated.

{
   "_id":<object_id>,
   "column1":"value1",
   "column2":"value2",
   "_createdAt":{"$date":<create_date>},
   "_updatedAt":{"$date":<update>}
}
Examples

Retrieving an object with ID 57928860e4b00ef864f3dc24. The collection has six columns:

  • firstName (String)
  • lastName (String).
  • courses (Array).
  • isTransferStudent (Boolean).
  • Major (Object).
  • toAddress (Pointer to Address collection).
var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.retrieveObject(dbApiKey, "Student", "57a51664e4b03647ddae3294");
{
    "courses": [
        100,
        200,
        202
    ],
    "lastName": "Lee",
    "firstName": "Anna",
    "_createdAt": {
        "$date": "2016-08-05T23:56:06.051Z"
    },
    "_id": "57a52796e4b03647ddae32a5",
    "major": {
        "name": "Computer Science"
    },
    "toAddress": {
        "collName": "Address",
        "_id": "57a5199be4b03647ddae3297"
    },
    "isTransferStudent": false,
    "_updatedAt": {
        "$date": "2016-08-05T23:58:39.891Z"
    }
}
In this example the referenced collection (Address) data is also retrieved:
var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.retrieveObject(dbApiKey, "Student", "57a51664e4b03647ddae3294", "toAddress");
{
    "_createdAt": {
        "$date": "2016-08-05T23:56:06.051Z"
    },
    "courses": [
        100,
        200,
        202
    ],
    "toAddress": {
        "City": "Los Angeles",
        "_updatedAt": {
            "$date": "2016-08-05T22:56:32.455Z"
        },
        "_id": "57a5199be4b03647ddae3297",
        "_createdAt": {
            "$date": "2016-08-05T22:56:27.746Z"
        },
        "Street": "123 Main street"
    },
    "lastName": "Lee",
    "firstName": "Anna",
    "_updatedAt": {
        "$date": "2016-08-05T23:58:39.891Z"
    },
    "_id": "57a52796e4b03647ddae32a5",
    "major": {
        "name": "Computer Science"
    },
    "isTransferStudent": false
}