How to get only documents which have one field not empty - zend-framework

I'm trying to do create a query to exclude all documents which have an empty/null value in one specific field.
What is the query syntax or the programmatic way to do this?

You can use a required range query, which is open at both sides, like:
+field:[* TO *]
That is probably adequate, assuming that the documents to exclude have no value in the index.
If some form of default value appears, you would have to exclude that value as well, like:
+field:[* TO *] -field:NULL

Related

Cloud Firestore: check if value exists without knowing field name

I would like to check if a certain value is present in my Cloud Firestore collection through all the present fields and have back the document ID that has at least one field whose value is the one searched.
In this example, the code should give back only 2 records when I look for "Peter": 8cyMJG7uNgVoenA63brG and fnk0kgW7gSBc3EdOYWxD.
I know how to do a search when the field name is known. But in this case, I cannot know the field name at prior.
If you don't know the name of a field, you can't perform any queries against its value. Firestore requires queries to use some index, and indexes always work with the names of fields in your documents.

How to check whether a certain field is indexed in mongodb or not?

I know db.collection.getIndexes() can return all the indexes in collection, but sometimes it will return a long result if collection has many indexes, and this will make it difficult for you to find whether a certain field is indexed.
So how can you check whether a certain field is indexed in mongodb?
Yes, you can easily view whether you field is indexed or not using below query:
db.collection.stats().indexSizes().c2_YOUR_FIELD_NAME
In above query, use your own collection name and field name. If it returns some value on console, the field is indexed.
THIS will give you much indepth-knowhow

CouchDB filtering on key array

Given a CouchDb view that emits like this:
emit([doc.name, doc.date], doc)
How to filter on multiple doc.name values? Below doesn't seem to work.
keys=[["name1",{}],["name2",{}],["name3",{}]]
When you specify the keys parameter, you are specifying an exact match. Assuming you want a range query (every document with name="name1" no matter the date) then you need to query with a startkey and an endkey:
?startkey=["name1", ""]&endkey=["name1", {}]
And will have to repeat the query for each name.

Mongo query for number of items in a sub collection

This seems like it should be very simple but I can't get it to work. I want to select all documents A where there are one or more B elements in a sub collection.
Like if a Store document had a collection of Employees. I just want to find Stores with 1 or more Employees in it.
I tried something like:
{Store.Employees:{$size:{$ne:0}}}
or
{Store.Employees:{$size:{$gt:0}}}
Just can't get it to work.
This isn't supported. You basically only can get documents in which array size is equal to the value. Range searches you can't do.
What people normally do is that they cache array length in a separate field in the same document. Then they index that field and make very efficient queries.
Of course, this requires a little bit more work from you (not forgetting to keep that length field current).

Is there a way to fetch max and min values in Sphinx?

Im using sphinx for document search. Each document has list of integer parameters, like "length", "publication date (unix)", popularity, ... .
The search process itself works fine. But is there a way to get a maximum and minimum fields values for a specified search query?
The main purpose is to generate a search form which will contain filter fields so user can select document`s length.
Or maybe there is another way to solve this problem?
It is possible if length, date etc are defined as attributes.
http://www.sphinxsearch.com/docs/current.html#attributes
Attributes are additional values
associated with each document that can
be used to perform additional
filtering and sorting during search.
Try GroupBy function by 'length' and select mix(length), max(lenght).
In SphinxQl it is like:
select mix(length), max(lenght) from index_123 group by length
The same for other attributes.