MongoDb doesn't have joins. If the associated data is small enough, then it's suggested to embed the document.
If you take that appoarch, then you could perform this simple query to check if the embedded document field is a document.
0 < db.products.count({_id : 3, rebateProgram : { $type : 3} })
In mongoose, I think it's
0 < productModel.find({}).where({_id : 3, rebateProgram : { $type : 3} }).count()
rebateProgram : {$type : 3}
means only match the rebateProgram field if it's an with an embedded document.
3 is the BSON type for embedded document.
RESTful URL
A restful url to check the a property on a document could look like this.
The request would be a GET because you're retrieving a value and not modifying anything data.
GET: /??/:collectionName/:documentId/action
Example:
Request:
GET: /api/products/3/status?hasObject=rebateProgram
Response:
{
id: 3,
hasObject : { rebateProgram : true },
success : true,
errMsg : ""
}
However if it's always going to be the same field you're checking for, then include the status of the embedded field in the response.
Like this.
Example:
Request:
GET: /api/products/3/status
Response:
{
id: 3,
hasValidRebateProgram : true,
success : true,
errMsg : ""
}
More info: