'mongo - insert documents to other collection based on query

I am trying to insert documents to a collection based on a query
So I wrote the query, and then for each,
How do I read info from the "doc" result document from the first query to the insert statement?

 db.printer.find({"color":{$ne:null},"isDeleted":false}, {desc:1,identifier:1,_id:0}).forEach(function (doc) {

db.inventory.insertOne({ item: "printer", identifier: "<NEED DATA FROM DOC>" );

});


Solution 1:[1]

As Neil Lunn pointed the answer should be to use doc.identifier[object_name.identifier]. I am writing the answer because it might be useful to someone ,who might think that the question is not answered.
And to use .bulkWrite(), please follow

var bulk = db.inventory.initializeUnorderedBulkOp(); 
   db.printer.find({"color":{$ne:null},"isDeleted":false}, {desc:1,identifier:1,_id:0}).forEach(function (doc) {
bulk.insert( { item: "printer", identifier: doc.identifier );
});
bulk.execute();

You can use OrderedBulkOP or UnorderedBulkOp but Mongo groups the operations by the operation type and contiguity.Each group of operations can have at most 1000 operations. If a group exceeds this limit, MongoDB will divide the group into smaller groups of 1000 or less. So you dont need to worry about committing it for every 500 or so operations

Solution 2:[2]

This can be done in a single command with an aggregation pipeline and the $out or $merge operator.

Example:

db.printer.aggregate([
    {
        $match: {
            color: { $ne: null },
            isDeleted: false,
        },
    }, {
        $project: {
            item: 'printer',
            identifier: '$identifier',
        },
    }, {
        $merge: {
            into: 'inventory',
        },
    }
]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nav3916872
Solution 2 lukasvo