Using Mongoose JS to get array of pointer values for document, and expand return

What I am trying to do is the following.

I have objects that could live in multiple documents, and although I am not sure if this is best practice, I am using their ObjectId as pointers.

Document A

{
"_id": {
    "$oid": "51a02dade4b02780aeee5ab7"
},
"title": "My Document A",
"artifacts": [
    "51a81d8ee4b084336fea2d33",
    "asdfsdfe4b084336fea2d33"
]

}

Document B

{
"_id": {
    "$oid": "51a02dade4b02780aeee5ab7"
},
"title": "My Document A",
"artifacts": [
    "51a81d8ee4b084336fea2d33",
    "123454b084336fea2d33"
]

}

The individual artifact looks something like. If this artifact changes then there is no need to update the documents that it lives in:

{
    "_id": {
        "$oid": "51a81d8ee4b084336fea2d33"
    },
    "title": "Artifact A",
    "media": {
        "player": "video",
        "source": "http://www.youtube.com/watch?v=12334456"
    }
}

What I'd like to do, is get an expanded list of all the artifacts shown in either doc A or doc B in an array something like:

[{
        "_id": {
            "$oid": "51a81d8ee4b084336fea2d33"
        },
        "title": "Artifact A",
        "media": {
            "player": "video",
            "source": "http://www.youtube.com/watch?v=12334456"
        }
    },
{
        "_id": {
            "$oid": "123455e4b084336fea2d33"
        },
        "title": "Artifact B",
        "media": {
            "player": "video",
            "source": "http://www.youtube.com/watch?v=12334456"
        }
    }]

The way I have done it in the past is by POSTing from client a list of Ids and then using

{_id: { $in: userQuestArray} } 

but if i am constantly posting back to node from the client it seems a bit inefficient. Especially if the array I am posting is hundreds of items long.

Mongoose provide you a feature population which exactly does the same thing you are looking for http://mongoosejs.com/docs/populate.html. In your case what you need to do is

var mongoose = require('mongoose')
, Schema = mongoose.Schema

var tempSchema = Schema({    
title    : String,   
artifacts : [{ type: Schema.Types.ObjectId, ref: 'Artifacts' }]
});

var artifactsSchema = Schema({    
title    : String,   
media : { player: String, source: String, }
});

var tempModel  = mongoose.model('Temp', tempSchema);
var artifactsModel = mongoose.model('Artifacts', artifactsSchema);

Now whenever artifacts documents gets created you need to push that in respective temp dcoument artifacts array as shown in mongoose documentation. You can retrive it like that

tempModel
    .find(query)
    .populate('artifacts')
    .exec(function (err, results) {
        if (err)
            console.log(err);

        console.log(results);
    })
 //results contains data in form shown below
 [{
   "_id": {
     "$oid": "51a02dade4b02780aeee5ab7"
    },
   "title": "My Document A",
   "artifacts": [{
    "_id": {
        "$oid": "51a81d8ee4b084336fea2d33"
    },
    "title": "Artifact A",
    "media": {
        "player": "video",
        "source": "http://www.youtube.com/watch?v=12334456"
    }
   },
   {
    "_id": {
        "$oid": "123455e4b084336fea2d33"
    },
    "title": "Artifact B",
    "media": {
        "player": "video",
        "source": "http://www.youtube.com/watch?v=12334456"
    }
   }]
 }]