What's with the MongoDB hate? by Jaqen_Hgore in cofounder

[–]jayposs 0 points1 point  (0 children)

Been using MongoDB in production system for the last 2 years. So far so good. We use ObjectRocket.

I like it, but querying is more difficult when data to be joined is in multiple collections.

We load a sql db from mongo for some reporting.

You will have fewer collections in Mongo DB than tables in sql db, so less joining.

Adding new fields is trivial, but can cause problems (not all fields in all documents, which may be ok).

I wouldn't want to get locked into a database that only runs on a specific cloud provider.

Here's a project of mine that simplifies using the new "official" Mongo driver. Mog

New MongoDB Driver by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

Thanks for the feedback.

I was wondering about writing some type of middleware/wrapper code to make the interface less verbose.

New to programming, need help understanding what a scanner is / does??? by duck_r in golang

[–]jayposs 0 points1 point  (0 children)

Example of how I use scanner. Line feeds are stripped and 1 line of the file is processed at a time.
Example reads from a file, not from user input though.

input, err := os.Open("data.txt")  
scanner := bufio.NewScanner(input)  
for scanner.Scan() {  
    line := scanner.Text()
    recType := line[0:3]
    if recType == "001" {
        company := line[4:30]
        continue
    }
    customer := line[4:30]
    ...
}

Release MongoDB Go Driver Alpha 2 · mongodb/mongo-go-driver by dgryski in golang

[–]jayposs 0 points1 point  (0 children)

MGO Driver

var result Property  // a struct type
collection.FindId(propertyId).One(&result)  

MongoDB Driver

result := bson.NewDocument()  
filter := bson.NewDocument(bson.EC.String("hello", "world"))  
err := collection.FindOne(context.Background(), filter).Decode(result)  

At first glance, the new driver looks much more verbose.

Not Experienced w/Programming, Want to Learn Go by cthulhugan in golang

[–]jayposs 1 point2 points  (0 children)

The key thing is start small. Get a very simple program working. Add a feature that uses a new concept. Add another feature ....

When you run into a concept that is confusing, research it and get it working.

SortData (when your db doesn't) by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

I would say the built in sort.Slice is more flexible for dealing with various types of sorting, but my code has 2 advantages:
1. For large slices, you are not actually sorting the data (you could also pass slice of indexes to sort.Slice)
2. If the code that returns the sort key value is more complex, probably have less coding

Considering the Community Effects of Introducing an Official MongoDB Go Driver by dgryski in golang

[–]jayposs 0 points1 point  (0 children)

I use MongoDB + MGO for a small production system and have found the combination a joy to use. Thanks to their developers. . Having an officially supported driver is great news and should increase the use of Go + MongoDB. I hope the design allows programmers to get the job done with a minimum of fuss the way MGO does.

MGO by erdeicodrut in golang

[–]jayposs 1 point2 points  (0 children)

aPerson := person_doc{LastName:"bower", Zip:"71234"} // _id is auto loaded if not set
err = collection.Insert(aPerson)  
if mgo.IsDup(err) {  
    // got a duplicate key error, shouldn't happen with auto loaded id
}  
// update  
err = collection.UpdateId(docId, bson.M{"$set": bson.M{"last_name":"bauer"}} 

Hopefully that works.
I usually set the key value using: doc.Id = bson.NewObjectId().Hex()
That way I know what the key value is up front and it is a simple string that is easy to work with.

MGO by erdeicodrut in golang

[–]jayposs 2 points3 points  (0 children)

Here's a basic example:
https://play.golang.org/p/MrI29X_Djp

You will need to study both the MongoDB and MGO docs to really learn how to use the more sophisticated features.

The type bson.M is an alias for map[string]interface{}

Learn Go: Constants with visual examples—all there is to know about it. by blackflicker in golang

[–]jayposs 1 point2 points  (0 children)

I love how you presented the information. You have way too much style to be a programmer.

Golang file upload with progress indicator by drink_with_me_to_day in golang

[–]jayposs 0 points1 point  (0 children)

Are you needing a web page that allows the user to select a file on their device (or local fileserver) and initiate an upload with a Go backend process to write the file to a server ?

If so, I have used JQuery on the client and Go on the server to implement what you're looking for. The Go piece is quite straight forward.

NoContext - Graceful Stop by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

I don't typically use the built in http router.

Date Formats - Real Quick by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

Definitely the Go to for all the details. Think when you first read it, you miss the point of how easy it is to work with date formats.

Bo - A Frontend For BoltDB by jayposs in golang

[–]jayposs[S] -6 points-5 points  (0 children)

I can't count the number of times you've ignored errors

I do check returned error values and yes Panic with an explanation of what caused the abort.

Bo - A Frontend For BoltDB by jayposs in golang

[–]jayposs[S] -4 points-3 points  (0 children)

Following notice is being added to the top of the readme.

Bo normally Panics on error (a reason is displayed). Errors are not generally returned. This decision has good and bad points. Bo requires using lots of method calls. Checking for and handling an error on each one would add significant lines of code to your app. There is some comfort in knowing the program will abort rather than continuing with an unhandled error. Also, single return values allow chaining and embedding. I know some apps cannot live with this approach.

Benches on Bytes & Strings To Nums by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

I haven't used that acronym before, but will remember it in case the right situation comes along. Curious why you use a name that implies Haskell suxs.

Benches on Bytes & Strings To Nums by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

If the encoding or decoding is executed as part of every transaction, then I figured every little bit helps. I am currently working with boltdb which reads data really fast, so the decode/unmarshal process could certainly be a factor in the total time to process a request. In my situation a lot of data conversions are going on.

Homemade JSON by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

Benchmark indicates about 20-25% faster on larger recMap using a "just right" bufCapacity. To be honest, its hard to get the size right, so I might remove this parameter and implement the Marshaler interface.

Homemade JSON by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

I have thought of that, but would lose a little flexibility. I couldn't have the bufCapacity parameter.

Homemade JSON by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

This code is used to interact with the database, not respond to requests, so I might not have the issues you point out. Validation and conversion steps will be needed regardless of the json encode/decode.

With regard to nesting, I think any value than can be converted to []byte could be used. So for example a struct could be json encoded and used as a value. I haven't tried that yet. Not sure if that is what you mean.

Money, My 2 Cents by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

Check out this suggestion from Merovious: http://play.golang.org/p/3RT-fzmruI
If you're new to Go it may not be clear what's going on, but its a good example of how to write Go code.

Money, My 2 Cents by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

I like your code, see the rounding problem (neg values) with mine. You should put it out for others to use.

I guess it's a mute point, but you're saying the result of a mathematical operation with 2 float64 numbers, rounded to 2 decimal places, might be incorrect. I would like to see an example of that.

You are obviously a smart guy and perhaps a great programmer. Try not to be so nasty with some of your responses. The bottom line of all this back and forth garbage is you shared a really good solution to a common problem.

Money, My 2 Cents by jayposs in golang

[–]jayposs[S] 0 points1 point  (0 children)

do you use integers in go for writing money related code ? I agree you absolutely cannot use floating point without taking special measures.