• 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!

  • 相关阅读:
    event.preventDefault()
    laravel 授权使用gate门类
    Redis在Laravel项目中的应用实例详解
    Laravel实现找回密码及密码重置的例子
    2016-2017中国房地产走势大数据报告亮相
    特许金融分析师 (CFA) 持证人现在一般在做什么工作?职业分布是怎样的?
    工作中最常用的Excel函数公式大全
    151项国家职业资格目录清单公示
    中国 世界十大投资风云人物,谁是自己的指路明灯!
    世界十大投资风云人物,你知道几个?
  • 原文地址:https://www.cnblogs.com/harrysun/p/3945936.html
Copyright © 2020-2023  润新知