zoukankan      html  css  js  c++  java
  • bee go + mgo

    I am focusing on this project:  http://www.goinggo.net/2013/12/sample-web-application-using-beego-and.html  this weekend.

     see:  http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/

    1. install MongoDB

    1) install MongoDB

    2) start MongoDB as a services

    run cmd as Administrator

    mkdir c:datadb
    mkdir c:datalog
    
    echo logpath=c:datalogmongod.log> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"
    echo dbpath=c:datadb>> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"
    
    sc.exe create MongoDB binPath= ""C:Program FilesMongoDB 2.6 Standardinmongod.exe" --service --config="C:Program FilesMongoDB 2.6 Standardmongod.cfg"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
    

     

    If successfully created, the following log message will display:

    [SC] CreateService SUCCESS

     

    Start the MongoDB service.

    net start MongoDB

    Stop or remove the MongoDB service as needed.

    To stop the MongoDB service, use the following command:

    net stop MongoDB
    

    To remove the MongoDB service, first stop the service and then run the following command:

    sc.exe delete MongoDB

    2. Mgo

    1) download mgo , see http://labix.org/mgo

    go get gopkg.in/mgo.v2

    2) test mgo

     1 package main
     2 
     3 import (
     4         "fmt"
     5     "log"
     6         "gopkg.in/mgo.v2"
     7         "gopkg.in/mgo.v2/bson"
     8 )
     9 
    10 type Person struct {
    11         Name string
    12         Phone string
    13 }
    14 
    15 func main() {
    16         session, err := mgo.Dial("server1.example.com,server2.example.com")
    17         if err != nil {
    18                 panic(err)
    19         }
    20         defer session.Close()
    21 
    22         // Optional. Switch the session to a monotonic behavior.
    23         session.SetMode(mgo.Monotonic, true)
    24 
    25         c := session.DB("test").C("people")
    26         err = c.Insert(&Person{"Ale", "+55 53 8116 9639"},
    27                    &Person{"Cla", "+55 53 8402 8510"})
    28         if err != nil {
    29                 log.Fatal(err)
    30         }
    31 
    32         result := Person{}
    33         err = c.Find(bson.M{"name": "Ale"}).One(&result)
    34         if err != nil {
    35                 log.Fatal(err)
    36         }
    37 
    38         fmt.Println("Phone:", result.Phone)
    39 }

    run and you will get the result as

    Phone: +55 53 8116 9639
    

    3. the whole project

    Good luck!

  • 相关阅读:
    Mysql 时间操作
    curl 学习
    CURL详解
    mysql 获取当前时间戳
    php开启openssl的方法
    0,null,empty,空,false,isset
    ecshop微信扫描支付开发
    seaJs的简单应用
    js运动框架之掉落的扑克牌(重心、弹起效果)
    js运动框架完成块的宽高透明度及颜色的渐变
  • 原文地址:https://www.cnblogs.com/harrysun/p/3945936.html
Copyright © 2011-2022 走看看