-1

I'm trying to find out if an Object (document) exists in a collection.

Here's what I've tried but I'm stuck.

@DbTable(name = "websites")
private MongoCollection websitesTable;

private boolean isInTable(String url) {
    FindOne p = websitesTable.findOne("{url: #}", url);
    return false;
}

How do I check, if given url is already in the collection? Any help appreciated.

4

1 回答 1

1

尝试这个:

return websitesTable.findOne("{url: #}", url)
                    .as(Map.class)
                    .iterator()
                    .hasNext();
于 2015-05-14T09:36:36.747 回答