Golang MgO querying and updating inline documents

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The syntax for finding and displaying specific key-value pairs in a MongoDB shell is:

> Db.logs.Find({},{"Log":1}){ "_id":"3a06384a40a8e587806f194c6c80253e","Log":"This is a test log" }{ "_id":"36BB718040A4362B8035EBD822125DBA","Log":"This is a test log"}
The above instruction is to find all documents and display key value pairs "log".

If you need to not display "_id" key value pairs, you can write this

> Db.logs.Find({},{"_id":0,"Log":1}){ "Log":"This is a test log" }{ "Log":"This is a test log"}

The MgO notation in Golang needs to be implemented with the Select () method in MgO, with the following code:

Err = D.find (Bson. m{}). Select (Bson. m{"log"1}). All (&RESULT1)

The syntax for updating inline document key-value pairs in MongoDB is as follows:

Err = collection. Update (Bson. m{"_id": 123456}, Bson. m{"$set": Bson. m{"Info.name": "New"}})

The above instruction function is to update the "name" key value pair under "info" in the 123456 document "_id".


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.