Home>Article>Database> Methods for mongodb query table fields, string interception and update

Methods for mongodb query table fields, string interception and update

不言
不言 forward
2019-03-30 11:04:09 4805browse

The content this article brings to you is about mongodb query table fields, methods of string interception and update. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The update() method is used to update an existing document. The syntax format is as follows:

db.collection.update( , , { upsert: , multi: , writeConcern:  } )

Parameter description:

query: update query conditions, similar to what follows where in the sql update query.
update: update object and some update operators (such as $, $inc...), etc., can also be understood as
upsert after set in the sql update query: optional, the meaning of this parameter is , if there is no update record, whether to insert objNew, true means insert, the default is false, not insert.
multi: Optional, the default value of mongodb is false, and only the first record found is updated. If this parameter is true, all multiple records found according to the conditions will be updated.
writeConcern: Optional, the level at which the exception is thrown.

Example:
Image replacement address, first fuzzy query, then replace

db.pfs_merchants.find({'logo_url': /10.2.121.170/}).forEach(function(user) { user.logo_url = user.logo_url.replace("10.2.121.170","10.128.3.80"); print(user.logo_url); db.pfs_merchants.update({"_id":user._id},{$set:{"logo_url":user.logo_url}}); })

This article is over here, for more other exciting content, you can pay attention to the PHP Chinese websitemongodb video tutorialcolumn!

The above is the detailed content of Methods for mongodb query table fields, string interception and update. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete