Git Product home page Git Product logo

gomongo's People

Contributors

chbug avatar mikejs avatar phillyqueso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gomongo's Issues

Unmarshal doesn't work for maps

Test Program:

package main

import (
  "fmt"
  "github.com/mikejs/gomongo/mongo"
)

func main() {
  in := map[string]string {"foo": "test"}
  doc, err := mongo.Marshal(in)
  if err != nil {
    println(err)
  }
  b := doc.Bytes()
  fmt.Printf("%#v\n", string(b))
  ret := make(map[string]string)
  _ = mongo.Unmarshal(b, &ret)
  fmt.Printf("%v\n", ret)
}

Here's the output:
"\x13\x00\x00\x00\x02foo\x00\x05\x00\x00\x00test\x00\x00"
map[foo:]

I managed to get this working by adding a call to b2.Flush() to the Parse() function in bson.go at the end of the switch statement. Not sure if that's the right thing to do:

499       b2.Int64(int64(ui64))
500     default:
501       err = os.NewError(fmt.Sprintf("don't know how to handle kind %v yet", kind))
502     }
503     b2.Flush()
504 
505     kind, _ = buf.ReadByte()

gomongo doesn't understand result of getlasterror command

The following code demonstrates this problem.


package main

import (
    "github.com/mikejs/gomongo/mongo"
    "fmt"
    "os"
)

func main() {
    conn, _ := mongo.Connect("127.0.0.1")
    collection := conn.GetDB("test").GetCollection("test_collection")
    doc, _ := mongo.Marshal(map[string]string{
        "_id":     "doc1",
        "title":   "A Mongo document",
        "content": "Testing, 1. 2. 3.",
    })
    collection.Insert(doc)
    doc, err := mongo.Marshal(map [string]string{"getlasterror" : "1"})
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    doc, err = conn.GetDB("test_collection").Command(doc)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    m := make(map[string]string)
    err = mongo.Unmarshal(doc.Bytes(), m)
    if err != nil {
//DEBUG, the error is here
        fmt.Println(err)
        os.Exit(1)
    }
    collection.Drop()
}

Install error with net.ResolveTCPAddr

I'm using the latest build of go from hg repo. And when I try to install gomongo here it is:

$ goinstall github.com/mikejs/gomongo/mongo
goinstall: === cd /home/alex/Projects/other/go/src/pkg/github.com/mikejs/gomongo/mongo; gomake -f- install
8g -o go.8 bson.go cursor.go main.go connection.go message.go bson-struct.go collection.go database.go
connection.go:31: not enough arguments in call to net.ResolveTCPAddr
bson-struct.go:25: undefined: reflect.MapValue
bson-struct.go:32: cannot type switch on non-interface value v (type reflect.Value)
bson-struct.go:33: undefined: reflect.FloatValue
bson-struct.go:40: cannot type switch on non-interface value v (type reflect.Value)
bson-struct.go:41: undefined: reflect.FloatValue
bson-struct.go:42: cannot use f (type float64) as type reflect.Value in function argument
bson-struct.go:47: cannot type switch on non-interface value v (type reflect.Value)
bson-struct.go:48: undefined: reflect.IntValue
bson-struct.go:49: cannot use i (type int64) as type reflect.Value in function argument
bson-struct.go:49: too many errors
make: *** [go.8] Error 1
--- exit status 2
goinstall: installing github.com/mikejs/gomongo/mongo: running gomake: exit status 2

authentication

the APIs are missing authentication... therefore, cannot connect to mongohq.

Goinstall fails on 6g 7015

Goinstall is failing on a recent Go checkout.

~/code> goinstall github.com/mikejs/gomongo/mongo
goinstall: === cd /Users/justin/go/src/pkg/unicode; /Users/justin/go/bin/gomake install
8g -o go.8 casetables.go digit.go letter.go tables.go
tables.go:45: syntax error: unexpected {, expecting }
tables.go:82: syntax error: unexpected {, expecting }
tables.go:222: syntax error: unexpected {, expecting }
tables.go:230: syntax error: unexpected {, expecting }
tables.go:329: syntax error: unexpected {, expecting }
tables.go:504: syntax error: unexpected {, expecting }
tables.go:508: syntax error: unexpected {, expecting }
tables.go:913: syntax error: unexpected {, expecting }
tables.go:917: syntax error: unexpected {, expecting }
tables.go:925: syntax error: unexpected {, expecting }
tables.go:925: too many errors
make: *** [go.8] Error 1
--- exit status 2
goinstall: installing unicode: running /Users/justin/go/bin/gomake: exit status 2

Suspicious because I'm on an amd64 OSX install, and goinstall is using 8g instead of 6g.

conflicting definitions for "os".File

My project isn't building after updating to 7188 release.2011-01-20:

6l: conflicting definitions for "os".File
/usr/local/share/go/pkg/linux_amd64/net.a(_go_.6):  type "os".File struct { fd int; name string; dirinfo *"os".dirInfo; nepipe int }
    func (f *"os".File) Chdir () "os".Error
    func (f *"os".File) Chmod (mode uint32) "os".Error
    func (f *"os".File) Chown (uid int, gid int) "os".Error
    func (file *"os".File) Close () "os".Error
    func (file *"os".File) Fd () int
    func (file *"os".File) Name () string
    func (file *"os".File) Read (b []uint8) (n int, err "os".Error)
    func (file *"os".File) ReadAt (b []uint8, off int64) (n int, err "os".Error)
    func (file *"os".File) Readdir (count int) (fi []"os".FileInfo, err "os".Error)
    func (file *"os".File) Readdirnames (count int) (names []string, err "os".Error)
    func (file *"os".File) Seek (offset int64, whence int) (ret int64, err "os".Error)
    func (file *"os".File) Stat () (fi *"os".FileInfo, err "os".Error)
    func (file *"os".File) Sync () "os".Error
    func (f *"os".File) Truncate (size int64) "os".Error
    func (file *"os".File) Write (b []uint8) (n int, err "os".Error)
    func (file *"os".File) WriteAt (b []uint8, off int64) (n int, err "os".Error)
    func (file *"os".File) WriteString (s string) (ret int, err "os".Error)
/usr/local/share/go/pkg/linux_amd64/github.com/mikejs/gomongo/mongo.a(_go_.6):  type "os".File struct { fd int; name string; dirinfo *"os".dirInfo; nepipe int }
    func (f *"os".File) Chdir () "os".Error
    func (f *"os".File) Chmod (mode uint32) "os".Error
    func (f *"os".File) Chown (uid int, gid int) "os".Error
    func (file *"os".File) Close () "os".Error
    func (file *"os".File) Fd () int
    func (file *"os".File) Name () string
    func (file *"os".File) Read (b []uint8) (n int, err "os".Error)
    func (file *"os".File) ReadAt (b []uint8, off int64) (n int, err "os".Error)
    func (file *"os".File) Readdir (count int) (fi []"os".FileInfo, err "os".Error)
    func (file *"os".File) Readdirnames (count int) (names []string, err "os".Error)
    func (file *"os".File) Seek (offset int64, whence int) (ret int64, err "os".Error)
    func (file *"os".File) Stat () (fi *"os".FileInfo, err "os".Error)
    func (f *"os".File) Truncate (size int64) "os".Error
    func (file *"os".File) Write (b []uint8) (n int, err "os".Error)
    func (file *"os".File) WriteAt (b []uint8, off int64) (n int, err "os".Error)
    func (file *"os".File) WriteString (s string) (ret int, err "os".Error)

Unmarshalling typed structs that contain slices of typed structs fail

Hey there

I had been using gomongo for a while until I discovered that the Unmarshal for a complex typed struct which contains a slice of other typed structs fails

If you take the example I created here :

http://go.hokapoka.com/golang/mongodb-golang-gomongo/

type ExampleDoc struct {
Title string
Body string
Comments []Comment
}

type Comment struct{
Author string
Web string
Message string
}

When Unmarshalling the ExampleDoc the slice of Comments is empty.

It appears that this issue has been resolved by Daniel Smith over on bitbucket : https://bitbucket.org/lavalamp/gomongo

I've not had a chance to apply any fixes to this master branch, if anyone has the time I would love to see the fix merged into this project.

Many thanks.

Andy

not compiling: bytes.Add missing

Hi Mike,

It seems that bytes.Add(..) is not part of the current Go release.
Would you be able to fix this so hat gomongo compiles again?

Thanks,
--Petar

Hi, Could you think about adding a function to collection.go?

HI, I am using gomongo in my project and thank you for your great work!
Now I want to use SKIP and LIMIT on the query, so I added a function to the library.
the diff is really simple one:

mongo $ git diff
diff --git a/mongo/collection.go b/mongo/collection.go
index 87ccccd..8471c01 100644
--- a/mongo/collection.go
+++ b/mongo/collection.go
@@ -117,6 +117,10 @@ func (self *Collection) Query(query BSON, skip, limit int32) (*Cursor, os.Error)
        return &Cursor{self, reply.cursorID, 0, reply.documents}, nil
 }
 
+func (self *Collection) FindAllWithOptions(query BSON, skip int32, limit int32 ) (*Cursor, os.Error) {
+       return self.Query(query, skip, limit)
+}
+
 func (self *Collection) FindAll(query BSON) (*Cursor, os.Error) {
        return self.Query(query, 0, 0)
 }

I think many may want SKIP/LIMIT when querying, so above patch could be welcomed by many.

col.Find with regexp /foo/ fails

I'd like to query using mongo's regexp search, for example :

db.mycollection.find( { name:/foo/ } )

Where it will match any documents whose "name" property contains "foo"

I have tried to use:

q := map[string]string{
  "name":"/foo/",
}

But it will only match on name that exatcly match the string "/foo/",
as you would expect.

So I tried to use go lang's regexp package for example :

===================================

package main


import (
   mongo "github.com/mikejs/gomongo/mongo"
   "regexp"
)

func main(){

   conn, _ := mongo.Connect("127.0.0.1")
   db := conn.GetDB("test")
   col := db.GetCollection("mycollection")


   q, _ := mongo.Marshal(map[string]interface{}{
       "name":regexp.MustCompile("/foo/"),
   })

   col.FindOne(q)

}

But it panics at runtime, I've attached the output at the bottom.

I wasn't sure if I should be using the regexp Package or some other
type to pass. I've looked through the tests and can't see regexp
used.

Have you got any suggestions.

panic: runtime error: invalid memory address or nil pointer dereference                                                                            

panic PC=0x7f5624538d50
runtime.panic+0xa7 /home/andrew/go/src/pkg/runtime/proc.c:1065
    runtime.panic(0x49408c, 0x7f562457c680)
runtime.panicstring+0x69 /home/andrew/go/src/pkg/runtime/runtime.c:83
    runtime.panicstring(0x5c0a5f, 0x2200000004)
runtime.sigpanic+0x144 /home/andrew/go/src/pkg/runtime/linux/thread.c:286
    runtime.sigpanic()
github%2ecom/mikejs/gomongo/mongo.*opQuery·Bytes+0x1d9 /home/andrew/go/src/pkg/github.com/mikejs/gomongo/mongo/message.go:179
    github%2ecom/mikejs/gomongo/mongo.*opQuery·Bytes(0x7f5624556870, 0x200000008, 0x7f5624538f18, 0x7f5624538f08)
github%2ecom/mikejs/gomongo/mongo.*Connection·sendMessageToReply+0x38 /home/andrew/go/src/pkg/github.com/mikejs/gomongo/mongo/collection.go:49
    github%2ecom/mikejs/gomongo/mongo.*Connection·sendMessageToReply(0x7f562457c580, 0x7f56245568a0, 0x7f5624556870, 0x7f560383065c, 0x7f5624556870
github%2ecom/mikejs/gomongo/mongo.*Collection·Query+0x104 /home/andrew/go/src/pkg/github.com/mikejs/gomongo/mongo/collection.go:104
    github%2ecom/mikejs/gomongo/mongo.*Collection·Query(0x7f5624558540, 0x0, 0x0, 0x100000000, 0x7f5624538ff0, ...)
github%2ecom/mikejs/gomongo/mongo.*Collection·FindOne+0x50 /home/andrew/go/src/pkg/github.com/mikejs/gomongo/mongo/collection.go:124
    github%2ecom/mikejs/gomongo/mongo.*Collection·FindOne(0x7f5624558540, 0x0, 0x0, 0x0, 0x7f5624556420, ...)
main.main+0x166 /home/andrew/testgomonog/main.go:59
    main.main()
runtime.mainstart+0xf /home/andrew/go/src/pkg/runtime/amd64/asm.s:77
    runtime.mainstart()
runtime.goexit /home/andrew/go/src/pkg/runtime/proc.c:148
    runtime.goexit()

goroutine 2 [3]:
runtime.entersyscall+0x28 /home/andrew/go/src/pkg/runtime/proc.c:572
    runtime.entersyscall()
syscall.Syscall6+0x5 /home/andrew/go/src/pkg/syscall/asm_linux_amd64.s:40
    syscall.Syscall6()
syscall.EpollWait+0x8d /home/andrew/go/src/pkg/syscall/zsyscall_linux_amd64.go:188
    syscall.EpollWait(0x7f5600000006, 0x7f562457c4b0, 0x100000001, 0xffffffff, 0xc, ...)
net.*pollster·WaitFD+0xfe /home/andrew/go/src/pkg/net/fd_linux.go:116
    net.*pollster·WaitFD(0x7f562457c3a0, 0x0, 0x0, 0x0, 0x0, ...)
net.*pollServer·Run+0xa3 /home/andrew/go/src/pkg/net/fd.go:207
    net.*pollServer·Run(0x7f562454c780, 0x0)
runtime.goexit /home/andrew/go/src/pkg/runtime/proc.c:148
    runtime.goexit()


Problem with FindAll and Query

I've got a problem querying db
with FindAll and Query.

FindAll and Query ( which is
also fired by FindAll ) returns
cursor which GetNext method
returns always nil BSON ( but
if e.g you have 10 records in db
it will return 10 nil BSONs ).

After checking tests for gomongo
I've noticed that it doesn't test
all values returned by FindAll.

I'm willing to help and contribute here
but I simple don't know where to
start, as the reason for such behaviour
on my machine could be e.g different
version of mongodb or something..

I've installed gomongo with goinstall
today and my mongodb version is 1.6.5

Find by Id

Hi all,

Is there currently any way to select records by it's Id ?
I've tried creating query map with "id_": ""
as well as creating query type with field Id_ []byte, both with
no success...

Query with limits returns whole collection

I've got about 100000 records in db.
I'd like to select only 10 of them.

so I write:

q, _ := mongo.Marshal(map[string]string{})
ret, error := coll.Query(q, 0, 10)

count := 200000 // because query gives me more than all of them....
keywords := make([]Keyword, count)

doc, _ := ret.GetNext()
for ; ret.HasMore(); doc, _ = ret.GetNext() {
fmt.Println("", iter)
mongo.Unmarshal(doc.Bytes(), &keywords[iter])
iter++
}

... and then I see about 100000 lines

0
1
2
...

101032
101033

So Query behaves ( maybe only on my machine ) just
like FindAll, no matter what limit and skip I give it..

I don't know if I'm doing something wrong or is there really
some problem with this method.

goinstall error

devMario-iMac:~ artieyoon_VB$ goinstall github.com/mikejs/gomongo/mongo
/bin/bash: === cd /Users/artieyoon_VB/Documents/go/src/pkg/github.com/mikejs/gomongo/mongo; bash gomake -f- install
6g -I "/Users/artieyoon_VB/Documents/go/pkg/darwin_amd64" -I "/Users/artieyoon_VB/Documents/go/pkg/darwin_amd64" -o go.6 bson-struct.go bson.go collection.go connection.go cursor.go database.go main.go message.go
bson-struct.go:25: undefined: reflect.MapValue
bson-struct.go:32: cannot type switch on non-interface value v (type reflect.Value)
bson-struct.go:33: undefined: reflect.FloatValue
bson-struct.go:40: cannot type switch on non-interface value v (type reflect.Value)
bson-struct.go:41: undefined: reflect.FloatValue
bson-struct.go:42: cannot use f (type float64) as type reflect.Value in function argument
bson-struct.go:47: cannot type switch on non-interface value v (type reflect.Value)
bson-struct.go:48: undefined: reflect.IntValue
bson-struct.go:49: cannot use i (type int64) as type reflect.Value in function argument
bson-struct.go:50: undefined: reflect.UintValue
bson-struct.go:51: cannot use uint64(i) (type uint64) as type reflect.Value in function argument
bson-struct.go:61: self.map_ undefined (type structBuilder has no field or method map)
bson-struct.go:62: self.map_ undefined (type *structBuilder has no field or method map_)
bson-struct.go:82: invalid type assertion: self.val.(_reflect.PtrValue) (non-interface type reflect.Value on left)
bson-struct.go:83: undefined: reflect.NewValue
bson-struct.go:117: invalid type assertion: self.val.(_reflect.StringValue) (non-interface type reflect.Value on left)
bson-struct.go:127: invalid type assertion: self.val.(_reflect.StringValue) (non-interface type reflect.Value on left)
bson-struct.go:136: invalid type assertion: self.val.(_reflect.BoolValue) (non-interface type reflect.Value on left)
bson-struct.go:145: invalid type assertion: self.val.(_reflect.SliceValue) (non-interface type reflect.Value on left)
bson-struct.go:160: invalid type assertion: self.val.(_reflect.SliceValue) (non-interface type reflect.Value on left)
bson-struct.go:171: cannot type switch on non-interface value self.val (type reflect.Value)
bson-struct.go:172: undefined: reflect.ArrayValue
bson-struct.go:174: too many arguments in call to v.Value.Elem
bson-struct.go:176: undefined: reflect.SliceValue
bson-struct.go:185: undefined: reflect.SliceType
bson-struct.go:193: too many arguments in call to v.Value.Elem
bson-struct.go:203: invalid type assertion: self.val.(reflect.PtrValue) (non-interface type reflect.Value on left)
bson-struct.go:205: undefined: reflect.MakeZero
bson-struct.go:208: self.map
undefined (type structBuilder has no field or method map)
bson-struct.go:211: invalid type assertion: self.val.(_reflect.MapValue) (non-interface type reflect.Value on left)
bson-struct.go:220: cannot type switch on non-interface value reflect.Indirect(self.val) (type reflect.Value)
bson-struct.go:221: undefined: reflect.StructValue
bson-struct.go:222: undefined: reflect.StructType
bson-struct.go:230: undefined: reflect.MapValue
bson-struct.go:231: undefined: reflect.MapType
bson-struct.go:232: undefined: reflect.Typeof
bson-struct.go:235: undefined: reflect.NewValue
bson-struct.go:236: too many arguments in call to v.Value.Elem
bson-struct.go:237: cannot convert nil to type reflect.Value
bson-struct.go:238: v.SetElem undefined (type reflect.Value has no field or method SetElem)
bson-struct.go:238: too many errors
make: *** [go.6] Error 1
--- exit status 2
goinstall: github.com/mikejs/gomongo/mongo: install: running bash: exit status 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.