0

EDIT DUPLICATE
I know that the way explained in the other questions works, but I'm asking something different, that is why the method I'm using is not working when it should

Following this question I've tried to delete all documents in my collection by doing this:

String collectionName = "functionalityLogs";
MongoCollection<LogFunctionDocument> collection =   MongoUtilities.getCollectionByName(collectionName, LogFunctionDocument.class); 
collection.deleteMany({});

The problem is that it gives me error in the method and tells me

Syntax error, type annotations are illegal here

Also in the docs for the current version the method is the same. What is wrong? I know I can use some "alternatives" like specifying an empty document, but I want to know where I'm wrong in using this method.

EDIT
I've also tried this as already said:

MongoCollection collection = myDB.getCollection(collectionName)

collection.deleteMany({});

But not working.
I know I can use BasicDBObject document = new BasicDBObject(); and pass it to deleteMany by doing collection.deleteMany(document); in fact is what I'm doing right now and it works, and also the DBCursors is an alternative, I'm just asking why the above method does not work when it should (or maybe it's all wrong and it shouldn't at all, at this point?).

Usr
  • 2,628
  • 10
  • 51
  • 91
  • @NeilLunn even if I do not assign a type to the collection, the error is still the same with deleteMany – Usr Apr 16 '19 at 10:12
  • Read the linked answer please as you appear to have not done so if you want to say you have not assigned a type to the collection. There's a clear difference between the answer code and yours. – Neil Lunn Apr 16 '19 at 10:15
  • @NeilLunn I've changed my code by not assigning the type to collection and just specifying the name as you suggested, I've not changed my code in the question because nothing has changed but I can edit it if is necessary. But even in this way the error persist. – Usr Apr 16 '19 at 10:22
  • I suggest that if you are actually reading the marked duplicate and trying it, then you **also** show in your question exactly what you have tried and what error that produces. Because it will not produce the error currently present in your question. Your not the first person in the world to do this, so existing answers are there to help you. Please understand that your question is not "randomly" closed, but you are pointed at something that a subject expert already knows will work. **Not working** tells us nothing. Error messages are things that happen when it does not work. – Neil Lunn Apr 16 '19 at 10:26
  • @NeilLunn I've edited the question. Hope now is clearer – Usr Apr 16 '19 at 10:26

0 Answers0