Skip to content Skip to sidebar Skip to footer

Updating A Collection From A Different Database

I'm using Mongo 4.1 and would like to update a collection named 'location_copy', by adding a new field to it of type object named 'time', with two subfields: 'utcTime', which will

Solution 1:

db.getSiblingDB().collection.find() is a client-side operation. It is not something you can use to join collections as part of a query. For that, see https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/.

The second thing you are doing is retrieving nested fields out of a document. You can do this with $set and dot notation. See specifically the example at https://docs.mongodb.com/manual/reference/operator/aggregation/set/#adding-fields-to-an-embedded-document.

You will need to construct a single aggregation pipeline that does everything your current mix of aggregation and javascript does using only the operations documented in https://docs.mongodb.com/manual/reference/operator/aggregation/ and the stages documented in https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/.


Post a Comment for "Updating A Collection From A Different Database"