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

Methods for mongodb query table fields, string interception and update

不言
Release: 2019-03-30 11:04:09
forward
5087 people have browsed it

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(
       <query>,
       <update>,
       {
         upsert: <boolean>,
         multi: <boolean>,
         writeConcern: <document>
       }
    )
Copy after login

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}});
 })
Copy after login

This article is over here, for more other exciting content, you can pay attention to the PHP Chinese website mongodb video tutorial column!

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template