Based on your use of the word query, I’m going to assume you’re referring to N1QL queries.
Yes, it is possible to query all documents and then exclude given keys using the WHERE clause. However, this can have very poor performance so I’d be careful with your use case.
To do so, use the META function. This returns an object with various document properties, one of which is “id”. This property is the document key.
Here is an example query based on your example, assuming the bucket name is “default”:
SELECT * FROM default WHERE META(default).id <> '18'
If you are using Linq2Couchbase, it can be represented as:
bucketContext.Query<DocType>().Where(p => N1QlFunctions.Key(p) != "18");