I am using the new Firestore query feature
firebase.firestore().collection("articles").where("tags", "array-contains", tag)
to query all the article with specific tags.
The query works fine but the result is not sorted.
I understand how database indexes work and use them with other string fields before but not yet with array type.
When I do the query
firebase.firestore().collection("articles").orderBy("publishTime", "desc").where("tags", "array-contains", tag)
It prompts a link to create index. But that link does not work.
Is this because the new feature is still under development or is there any special step for "array-contains" query type?
This is now resolved by create the index field under ARRAY type
Related
I am new to mongodb. So I don't know what is the better way to query array field. I have a schema where in our collection of courses we have a program field. In start it was Reference to program collection and contain program id. But Now we have change the schema from Reference to array of Reference, so we can allow course to be a part of multiple program. In our codebase all the query are written like this:
course.find({program});
Do I have to change this query to cater this schema change like this:
course.find({program: {$in: program}});
I have tested in mongodb compass and this query
course.find({program});
Work on array field.
So let me know what could be consequence if i don't use $in operator while search the array field.
I have been searching through the MongoDB query syntax with various combinations of terms to see if I can find the right syntax for the type of query I want to create.
We have a collection containing documents with an array field. This array field contains ids of items associated with the document.
I want to be able to check if an item has been associated more than once. If it has then more than one document will have the id element present in its array field.
I don't know in advance the id(s) to check for as I don't know which items are associated more than once. I am trying to detect this. It would be comparatively straightforward to query for all documents with a specific value in their array field.
What I need is some query that can return all the documents where one of the elements of its array field is also present in the array field of a different document.
I don't know how to do this. In SQL it might have been possible with subqueries. In Mongo Query Language I don't know how to do this or even if it can be done.
You can use $lookup to self join the rows and output the document when there is a match and $project with exclusion to drop the joined field in 3.6 mongo version.
$push with [] array non equality match to output document where there is matching document.
db.col.aggregate([
{"$unwind":"$array"},
{"$lookup":{
"from":col,
"localField":"array",
"foreignField":"array",
"as":"jarray"
}},
{"$group":{
"_id":"$_id",
"fieldOne":{"$first":"$fieldOne"},
... other fields
"jarray":{"$push":"$jarray"}
}},
{"$match":{"jarray":{"$ne":[]}}},
{"$project":{"jarray":0}}
])
I have a datastore query that filters on different props by equality, after debugging the query, i found that the 2nd filter only applies, the first one doesn't be taken by the query.
Here's the query:
Query<Entity> query = Query.newEntityQueryBuilder().setKind("locations")
.setFilter(StructuredQuery.PropertyFilter.eq("country",countryCode))
.setFilter(StructuredQuery.PropertyFilter.eq("type",locationTypeCode))
.build();
As far as i know, when filter on different props, it should work, but in my case doesn't apply?
I tried doing this recently myself, and from what I saw, adding multiple filters onto a query just overwrote the filter. Composite filters solve that problem. There's a section in the query documentation that may be useful: https://cloud.google.com/appengine/docs/standard/java/datastore/queries#query_interface_example
// Use CompositeFilter to combine multiple filters
CompositeFilter heightRangeFilter =
CompositeFilterOperator.and(heightMinFilter, heightMaxFilter);
// Use class Query to assemble a query
Query q = new Query("Person").setFilter(heightRangeFilter);
I have data in which field have following java data types.
What would be the best way to index such kind of data.
Thanks,
field_a map<string,string>
field b map<string,array<string>>
How to define schema.xml for it
Currently Solr doesn't support map type field type. So, you can not query on some particular key inside the map and retrieve its value. I don't know whether it'll be helpful you or not, but I can suggest you a way to keep this in Solr.
You can store the map in a field as a json formatted string. Say, document1 has map1 in field_a and document2 has map2 in field_a. Now, you keep some distinct data related to each map to their corresponding documents. When you want to query, query on those fields in stead of the maps. Then in the search result, when you retrieve the json formatted string, parse it in your application and get the values.
Hope this will help.
I am trying to make a query in solr.net that generates a solr query with a filter query with more than one term in it e.g.: fq=Size:(4 large)
However, when I pass ?f_Size=(4 large) in the query string to the SolrNet sample app (found here: http://code.google.com/p/solrnet/downloads/list), no results are found.
Looking at the logs, I can see that the filter query generated is fq=Size:"\(4+large\)" so it makes sense that no results are found.
Is there a way in SolrNet to generate a filter query with more than one term?
Where the filter queries are built, try replacing Query.Field(...).Is(...) with Query.Simple(...) (you have to build the query yourself). See the wiki for reference.