MongoDB-Java-Treiber - Nutzung besteht Projektion in der Suche-Abfrage
Möchte ich, um alle Dokumente, in denen das Feld download existiert nicht
find{ "download" : {$exists: false}}
Für Java fand ich ein Beispiel:
BasicDBObject neQuery = new BasicDBObject();
neQuery.put("number", new BasicDBObject("$ne", 4));
DBCursor cursor = collection.find(neQuery);
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
Meine Adaption ist
BasicDBObject field = new BasicDBObject();
field.put("entities.media", 1);
field.put("download", new BasicDBObject("$exists",false));
System.out.println("Start Find");
DBCursor cursor = collection.find(query,field);
System.out.println("End Find Start Loop ALL 100k");
int i = 1;
while(cursor.hasNext())
Die Vorhanden Zeile funktioniert nicht:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: com.mongodb.MongoException: Unsupported projection option: $exists
at com.mongodb.MongoException.parse(MongoException.java:82)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:314)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
at com.mongodb.DBCursor._check(DBCursor.java:368)
at com.mongodb.DBCursor._hasNext(DBCursor.java:459)
at com.mongodb.DBCursor.hasNext(DBCursor.java:484)
at ImgToDisk.main(ImgToDisk.java:61)
... 5 more
Haben keine Ahnung jetzt welche die richtige adaption wäre, da habe ich meine Abfrage funktioniert in der shell und mit UMongo der transfer auf java scheint nicht so einfach zu sehen.
Sie verweisen auf ein query-Objekt in Ihr finden () - Aufruf. könnte hilfreich sein, um zu zählen, dass in dem Beispiel
InformationsquelleAutor Dukeatcoding | 2013-04-09
Du musst angemeldet sein, um einen Kommentar abzugeben.
verwenden Sie
die DBObject, das ist der 2. parameter der find-Methode wird verwendet, um anzugeben, welche Attribute der resultierenden Dokumente, die Sie wollen, werden zurückgegeben. Es ist nützlich für die Verringerung der Last im Netzwerk.
In Ihrem Beispiel, Sie versuchen, ein $exists-Klausel in die
field
DBObject. Das wird nicht funktionieren.Der 2. parameter-Objekt nur Attributwerte von 1(dieses Attribut) oder 0(ausschließen).
Legen Sie es in den ersten DBObject genannt
query
statt.Siehe auch hier und hier
InformationsquelleAutor rompetroll
können Sie DBCollection zu tun, die mit JAVA-API
}
db ist MongoDataBase
InformationsquelleAutor LRBH10