Is it possible to copy certain fields from one collection to another?
I am looking to copy the values of 'bar' to the 'foo' collection, excluding the 'type' field. Additionally, I want to add a new _id and an extra field (userId) to 'foo' using Node.js.
collection bar
{
"_id" : ObjectId("77777777ffffff9999999999"),
"type" : 0,
"name" : "Default",
"index" : 1,
"layout" : "1",
}
collection foo
{
"_id" : NEW OBJECT ID,
// "type" : 0, NOT INCLUDED IN THIS COLLECTION
"userId" : ObjectId("77777777ffffff9999999911"),
"name" : "Default",
"index" : 1,
"layout" : "1",
}
I attempted using db.bar.copyTo("foo");
, but it copied the entire collection instead.