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!

  • 相关阅读:
    修改Matlab 2012b默认工作路径
    win7,M​i​n​d​m​a​n​a​g​e​r​2​0​1​2使用模板时弹出Runtime error R6025解决方法
    Win7 Qt4.8.5+QtCreator2.8.0+mingw配置过程
    RabbitMQ介绍和延迟队列
    FastDFS介绍
    SpringMVC的工作流程
    spring mvc入参有Date类型
    spring 定时任务的 时间配置cron表达式
    Transactional介绍及使用
    spring cloud 集成rabbitMQ实现延时队列
  • 原文地址:https://www.cnblogs.com/harrysun/p/3945936.html
Copyright © 2011-2022 走看看