内容简介:1、要安装mongodb数据库,2、要下载golang的mgo包,3、连接操作
开发十年,就只剩下这套 Java 开发体系了 >>>
1、要安装 mongodb 数据库,2、要下载golang的mgo包,3、连接操作
package main
import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"fmt"
)
const URL = "192.168.1.83:27017" //mongodb的地址
func main() {
session, err := mgo.Dial(URL) //连接服务器
if err != nil {
panic(err)
}
c := session.DB("ChatRoom").C("account") //选择ChatRoom库的account表
c.Insert(map[string]interface{}{"id": 7, "name": "tongjh", "age": 25}) //增
objid := bson.ObjectIdHex("55b97a2e16bc6197ad9cad59")
c.RemoveId(objid) //删除
c.UpdateId(objid, map[string]interface{}{"id": 8, "name": "aaaaa", "age": 30}) //改
var one map[string]interface{}
c.FindId(objid).One(&one) //查询符合条件的一行数据
fmt.Println(one)
var result []map[string]interface{}
c.Find(nil).All(&result) //查询全部
fmt.Println(result)
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- JavaScript骚操作之操作符
- Go 语言操作 MySQL 之 事务操作
- C# 数据操作系列 - 1. SQL基础操作
- Vim 跨行操作与 Ex 命令操作范围
- 并发环境下,先操作数据库还是先操作缓存?
- 关于HBase Shell基本操作的表操作示例
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Writing Apache Modules with Perl and C
Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95
Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!