MongoDB Batch Updates a field

Source: Internet
Author: User
Tags foreach mongodb openid
Db.getcollection (' my_booking '). Find ({"Hospitalname":/xx Hospital/,openid:/^2/}). ForEach (
   function (item) {                
       Db.getcollection (' my_booking '). Update ({"_id": item._id},{$set: {"PayType": "1"}}
)

Query out Hospitalname is XX hospital and OpenID all records beginning with 2, and update my_booking table in PayType is 1.

Db.getcollection (' my_booking '). Find ({"Hospitalname":/xx hospital/,openid:{$not:/^2/}}). ForEach (
   function (item) {                
       db.getcollection (' my_booking '). Update ({"_id": item._id},{$set: {"PayType": "2"}}
)

The query out Hospitalname is XX hospital and OpenID does not start with 2 of all records, and update my_booking table in the PayType is 2.

Db.getcollection (' my_booking '). Find ({"Hospitalname":/Yuncheng City Center Hospital/,openid:{$not:/^2/}}). ForEach (
   function (item) {                
       db.getcollection (' my_booking '). Update ({"_id": item._id},{$set: {"OutTradeNo1": Item.outtradeno2}})
   }
)

Check out all records of the XX hospital and the OpenID beginning with 2, and assign the OutTradeNo2 of each record to outTradeNo1.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.