Comments (4)
from bongo.
var parentColl *bongo.Collection
var childColl *bongo.Collection
type parent struct{
bongo.DocumentBase `bson:",inline"`
Childs []*Child
}
type Child struct{
bongo.DocumentBase `bson:",inline"`
ParentID bson.ObjectId
Status int
diffTracker *bongo.DiffTracker
}
func Test_Bongo(t *testing.T){
parentColl=utils.Bconn.Collection("parent")
childColl=utils.Bconn.Collection("child")
parent:=new(parent)
parentColl.Save(parent)
child:=new(Child)
child.ParentID=parent.Id
childColl.Save(child)
for i:=1;i<100;i++{
child.Status=i
childColl.Save(child) //will invoke CascadeSave using (goroutine CascadeSave)
//code: https://github.com/go-bongo/bongo/blob/master/collection.go#L147
}
//**the end**: len(parent.Childs)!=1 or parent.Childs[0].Status!=99
}
func (c *Child) GetCascade(collection *bongo.Collection) []*bongo.CascadeConfig {
connection := collection.Connection
rel :=c
cascadeMulti := &bongo.CascadeConfig{
Collection: connection.Collection("parent"),
//Properties: []string{"name","orgname","status"},
Data:rel,
ThroughProp: "childs",
RelType: bongo.REL_MANY,
Query: bson.M{
"_id": c.ParentID,
},
}
if c.diffTracker!=nil && c.diffTracker.Modified("ParentID") {
origId, _ := c.diffTracker.GetOriginalValue("ParentID")
if origId != nil {
oldQuery := bson.M{
"_id": origId,
}
cascadeMulti.OldQuery = oldQuery
}
}
return []*bongo.CascadeConfig{ cascadeMulti}
}
the end:
parent doccument error,
len(parent.Childs)!=1 or parent.Childs[0].Status!=99
from bongo.
or update this way
for i:=1;i<20;i++{
cloneChild:=*child
cloneChild.Status=i
childColl.Save(&cloneChild)
}
time.Sleep(2*time.Second)
the end:
parent doccument error,
len(parent.Childs)!=1 or parent.Childs[0].Status!=19
from bongo.
I could see this being a race condition if there are multiple users updating the same record. Solution seems to be just removing the go
in front of the CascadeSave
here https://github.com/go-bongo/bongo/blob/master/collection.go#L147
Can you submit a PR?
from bongo.
Related Issues (20)
- Not sure what "Cascading" does? HOT 2
- The FindOne example in README is incorrect. HOT 1
- How to Modify Element HOT 2
- mongodb3.0 SCRAM-SHA-1?
- Populate sintax
- can not auto connection ? HOT 2
- Project status? HOT 3
- Should Clone() replace with Copy() ? HOT 1
- looking forward to it
- mgo import path should be update. HOT 1
- questions
- Error while creating a collection
- Best way to check if exist with some conditions
- No Update() method? HOT 2
- how to remove/delete a collection? HOT 1
- How to find average?
- bongo is giving no reachable server error while trying to connect to mongodb cluster HOT 3
- No Bulk Insert Method ?
- Bongo does not support non-atlas mongo db servers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bongo.