mikejs / gomongo Goto Github PK
View Code? Open in Web Editor NEWGo driver for MongoDB
License: Other
Go driver for MongoDB
License: Other
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
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
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
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
Please support nil values. They are valid among BSOC specification. Currently this is not possible with gomongo
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.
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)
Collection.Insert do not raise Error when duplicate key ?
the APIs are missing authentication... therefore, cannot connect to mongohq.
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...
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()
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.
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()
}
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
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.
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()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.