I am trying to update documents of collection sale_order if sale_order['orderId'] exists in temp_sale_order. If it does not exists in temp_sale_order then a new document will be created in sale_order. (upsert).
But it only creates only one document in it.
If i use find instead of findOne. it throws an error:
Error:
uncaught exception: can't save a DBQuery object
My query:
db.getCollection('sale_order').update(
db.getCollection('sale_order').find({},{orderId:1}),
db.getCollection('temp_sale_order').findOne({},{orderId:1}),{upsert:true});
what is the correct way? Also how to write and use a function in mongodb with above query?