I'm in the process of writing a cleanup routine for a mongodb collection for a unit test via the java driver (i tried the "native" matlab driver but the documentation is, well, scarce).
I can get a connection going (at least i think i can), but i'm stuck at invoking the remove method on a DBCollection object.
I'm running the following code:
javaaddpath(pathToJarFile)
import com.mongodb.*;
mongoClient = MongoClient(mHost);
mongoConn = mongoClient.getDB(dbName);
auth = mongoConn.authenticate(user,password);
events = mongoConn.getCollection('events');
events.remove();
On the last line i get the error
No method 'remove' with matching signature found for class 'com.mongodb.DBCollectionImpl'.
Since i know that the ´remove´ method exists for the DBCollection class, i'm a bit at a loss currently.
Any help would be appreciated. Note that i'm essentially illiterate when it comes to OOP :-S
Edit:
Please note that i also tried
events.remove({});
which results in the same error message.
According to the API documentation of DBCollection.remove, you must provide a DBObject that simply specifies the deletion criteria. It further says to pass an empty document to delete all documents in the collection. At least you must provide an argument.
According to the documentation on how to remove all documents from a collection, you simply pass the argument {} indicating an empty document to that method. So you must call
events.remove( {} );
To answer your question in the comments: The argument must be a DBObject that describes the remove criteria. A cursor is not such a document.
It seems that {} isn't passed correctly by MATLAB, so creating an empty document and passing it to remove does indeed work.
The working code looks like this:
javaaddpath(pathToJarFile)
import com.mongodb.*;
mongoClient = MongoClient(mHost);
mongoConn = mongoClient.getDB(dbName);
auth = mongoConn.authenticate(user,password);
events = mongoConn.getCollection('events');
empty = BasicDBObject();
events.remove(empty);
Related
Following i my code in JCO3.0 to connect to RFC and get the data from function module:
try {
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME);
JCoFunction function = destination.getRepository().getFunction("funtion_abap");
***function.getImportParameterList().setValue("IM_ID_NAME", "MTC_ZPR008_TEMPB");***
function.execute(destination);
JCoTable table = function.getTableParameterList().getTable("export_table");
}
catch(Exception e){
}
Following is my ABAP function:
CALL FUNCTION 'funtion_abap' DESTINATION m_vsyid
EXPORTING
IM_ID_NAME = table_vname
IMPORTING
export_table = table_tvarvc
EXCEPTIONS
system_failure = 1
communication_failure = 2
resource_failure = 3
OTHERS = 4.
following is an error m getting while passing String as import parameter while it wants Table field as import parameter:
Exception in thread "main" com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert a value of 'MTC_ZPR008_TEMPB' from type java.lang.String to TABLE at field IM_ID_NAME
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:468)
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:462)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:2958)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:4074)
at com.amgen.rfc.RFC_Connection.main(RFC_Connection.java:47)
Please tell me how to solve this problem.
The RFC definition and your code are in direct opposition. According to the ABAP function (as far as I read it) the result of the call is the value in field IM_ID_NAME and the table is the input parameter.
I'm not 100% familiar with the declaration of RFCs in ABAP (I only know the Java side of it), but if I interpret the error message correctly, the table seems to be in the input parameter list rather than the table parameter list (not usual but not never seen before, either). So instead of getTableParameterList you will possible have to call getInputParameterList. Also you should omit the setting of the field IM_ID_NAME because that's the response value and resides in the output parameter list.
I know the question is quite old but someone may find my response useful one day since I had the same problem:
JcoTable tab = function.getImportParameterList().getTable("IM_ID_NAME");
tab.appendRow();
tab.firstRow(); // I'm not sure if this is actually reqiured
tab.setValue("PARAM_NAME", paramValue);
Hi i am new to groovy and i have an issue that i am facing. Currently i am trying to see the values inside typeCache[alias] which seems to be a hashtable.
protected static Hashtable typeCache = new Hashtable();
logger.error "this is type cache : " + typeCache[alias].get(indx)[1];
when i output the element i get the following result in the logs :-
this is type cache : [com.abcd.util.TypeElement#5dc97ce, com.abcd.util.TypeElement#270a8a6, com.abcd.util.TypeElement#5d421487]
am i able to expose further on the elements to see what is in them and what is it doing ?? i am used to php programming and usually in situations such as this i would do a var_dump is there an equivalent of var_dump in groovy ??
thank you.
Each object has a method, which generates a
public String dump()
Generates a detailed dump string of an object showing its class, hashCode and fields. http://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/Object.html#dump%28%29
This post contains an example, but make sure to read the comment, as the answer is not corrected as of yet.
I have an XPage that is saving a document inside SSJS with document1.save(). After this, I call some Java code to do some additional processing of the document and the new data that was saved; I pass document1.getDocument() in to the Java function. In the Java function, it calls Document.save() to save the document again. This seems to be a recipe for getting a save conflict, and I don't know why. Can anyone explain what's happening? TIA! (In addition to understanding why this is happening, if anyone has suggestions for a better way to do what I'm doing, I'd appreciate it.)
Reid
You can use "resolveVariable" in Java to get hold of your NotesXspDocument (which is called DominoDocument in Java). You can then do your save on the DominoDocument object in Java instead of in SSJS.
If you use JSFUtil (which is found in many XPages open source projects) or use your own helper method, you can then do this to get hold of your DominoDocument (replace "currentDocument" with the name of your document data source):
DominoDocument uidoc = (DominoDocument) JSFUtil.resolveVariable("currentDocument");
The resolveVariable method looks like this:
public static Object resolveVariable(final String variable) {
return FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance(), variable);
}
I'm having a weird problem with Couchbase Java API. I use the following code:
ViewQuery query = ViewQuery.from(BUCKET_NAME, GET_ENTITIES_VIEW_NAME);
...
// set companyStart, companyEnd as Strings
// set query.limit and query.skip
...
query.startKey(toJsonArray(companyStart, Long.toString(params.getStartDate().getTime())));
endKey(toJsonArray(companyEnd, Long.toString(params.getEndDate().getTime())));
ViewResult results;
results = bucket.query(query);
...
When I try the said start and endKeys (like ["ROTOR", 146538100000]) in the Couchbase console, the query returns all the expected results.
However, with the Java API the results is empty.
If I comment out the query.startKey and .endKey lines, it faithfully returns all the results for the view.
Here's my view:
function (doc, meta) {
if(doc.collectorData.documenttypes.terms[0] && doc.collectorData.documenttypes.terms[0]=='EAP:Article') {
emit([doc.collectorData.userdata.company,doc.timestamp], {"visitId":doc.visitId,"visitorId":doc.visitorId,"company":doc.collectorData.userdata.company,"timestamp":doc.timestamp, "userAgent":doc.userAgent, "pathInfo":doc.pathInfo, "channel":doc.collectorData.channel, "newVisit":doc.newVisit});
}
}
Any tips on what may be wrong?
You are using Long.toString, so it is not equivalent to what you used in the couchbase console.
That would be equivalent to ["ROTOR", "146538100000"]. A subtle but meaningful difference!
Try with the following snippet instead (I explicitly used JsonArray.from as well, just to remove any ambiguity):
query
.startKey(JsonArray.from(companyStart, params.getStartDate().getTime()))
.endKey(JsonArray.from(companyEnd, params.getEndDate().getTime()));
Simon's tips were most helpful. The mystery had a simple solution: I forgot to publish the view, and the old view only had one-field key, so the query was executing successfully yet returning nothing! A comment somewhere through the thread on https://forums.couchbase.com/t/not-able-to-get-all-rows-returned-from-couchbase-view/5020/23 provided the enlightenment.
I am attempting to write some script that simplifies table sorting and have been getting quite close but am now wondering if I have found a bug...or have just misunderstood limitations.
So my relevant code:
var reportRunnable = reportContext.getReportRunnable();
var reportDesign = reportRunnable.getDesignInstance();
var table = reportDesign.getTable(tableName);
var sortCondition = org.eclipse.birt.report.engine.api.script.element.StructureScriptAPIFactory.createSortCondition();
sortCondition.setKey("row[\"" + columnKey + "\"]");
sortCondition.setDirection("desc");
table.removeSortConditions();
table.addSortCondition(sortCondition);
I am getting a NullPointerException on line 164 in the class Listing:
org.eclipse.birt.report.engine.script.internal.element.Listing, in the method removeSortConditions...
((org.eclipse.birt.report.model.api.simpleapi.IListing) designElementImpl).removeSortConditions();
So the above implies 'designElementImpl' is null, having looked further at the source it seemed to imply that to instantiate the 'table' object, the following constructor was used:
public Table( TableHandle table );
And moving up the heirarchy of super classes, it implies that in the constructor of DesignElement, the following is returning null:
designElementImpl = SimpleElementFactory.getInstance( ).getElement(handle);
Any one any thoughts? Am I just not able to what I am trying to do?
Thanks in advance.
EDIT: Should probably add; I'm using BIRT 2.5.1.
I think I have this sorted now...I created a [simpler] new report without library dependencies and sorting is now working correctly.
I posted on another forum as well, so if anyone wants more details see BIRT Exchange Forums.
Cheers.