retrieveObject

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

Retrieves an object from a specified collection.

Parameters

The method has the following parameters:

ParameterDescriptionRequired
dbApiKeyDatabase API key.Yes.
tokenString with user session token or database master key.No.
collectionNameString with name of collection.Yes.
objectIdUnique identifier of the object that should be retrieved.Yes.
includeString parameter indicated should or shouldn’t include referenced object.No.
projJSON projection object that was built in accordance with the documentation of MongoDB query.No.

Response

A response will include the following fields:

ArgumentDescription
_idID of the object created.
columnXOne or more columns from this object.
_createdAtDate when the object was created.
_updatedAtDate 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
}