I think you should use a List
to record the indexs
List<Integer> indexs =new ArrayList<Integer>();
for (p = 0; p < array.length; p++) {
if(array[p]==search) {
indexs.add(p);
}
}
if(p.length()>0){
//print the result
}
That does work.
> db.test.insert({_id:"1", employees:[{ eid:"2", ename:"test", is_user:true }, { eid:"3", ename:"test2", is_user:true } ] })
> db.test.find({_id:"1","employees.eid":"2"});
{ "_id" : "1", "employees" : [ { "eid" : "2", "ename" : "test", "is_user" : true }, { "eid" : "3", "ename" : "test2", "is_user" : true } ] }
For the $
operator you want to use it like:
> db.test.insert({_id:"1", employees:[{ eid:"2", ename:"test", is_user:false }, { eid:"3", ename:"test2", is_user:false } ] })
> db.test.find({_id:"1", "employees.eid":"2", "employees.is_user": true});
> db.test.update({_id:"1", "employees.eid":"2"}, {$set: {"employees.$.is_user": true}});
> db.test.find({_id:"1", "employees.eid":"2", "employees.is_user": true});
{ "_id" : "1", "employees" : [ { "eid" : "2", "ename" : "test", "is_user" : true }, { "eid" : "3", "ename" : "test2", "is_user" : false } ] }
Notice how the insert of is_user
is set to false
on both objects in the array and after the update the matching object is updated from false
to true
, is that what you are looking for?
Best Answer
Merging these two examples is straightforward, and I created a JSFiddle to demo. First, add the definition of the arrow style to the SVG:
Then just add the marker to your
links
You end up with something like this:
You'll see that some arrows are bigger than others, because not all links have the same
stroke-width
. If you want to make all the arrows the same size, just modifywhen adding the links.