When I tried to store an array like test: []string{"hello", "bye"} using dgo and queried for test, I only get back "hello". Seems like the closest way to store an array in Dgraph is to create multiple objects and point them towards a single node. If that is the case, how would you store a list of fixed length? or ensure the number of list nodes does not exceed the intended list size (e.g. having a todo list with only 10 slots)?
You can create and get an array of string as follows
**Query to create array of strings**
{"set":[{
"StringArray" : ["Hi", "hello"]
}]}
**Query to fetch array of strings**
{q(func:has(StringArray)){
uid
StringArray
}}
In dgraph it is called as List Type
Ref: https://docs.dgraph.io/query-language/#list-type
Related
I have a list of user ids stored in a field of MongoDB collection. Each of the user ids is an UUID. The field is an array. For example,
["59cc7562-751b-11ed-a1eb-0242ac120002", "66e6f240-751b-11ed-a1eb-0242ac120002",
"742df8ea-751b-11ed-a1eb-0242ac120002", ............,"6cf6e398-751b-11ed-a1eb-0242ac120002"]
Now, if I want to check whether a user id is in the array, i need to do loop through the array until I find the user id or reach the end of the array. This is slow. I wonder if I can use a set to store the user ids instead of an array.
I am using Next.Js in the backend. If I convert the array to a set, that would be even slower than just looping through the array since the conversion takes o(n).
I've a problem with a query condition. I would like to query a string inside an array that's also inside a map. I manage to receive the information complet without the where condition but when I do this condition I've an error.
My function to retrieve all information
My array with a map inside
If category is the only value inside the produits array items, you can check for its existence with array-contains:
collectionRef.where('produits', arrayContains({ 'categorie': 'Alimentation' }))
If there are more properties for the array item, you will need to specify all of them in the call to arrayContains. There is no way to query for a subset of the array item.
In such cases, a common workaround is to add a extra array field to the document with just the property values you want to query for. For example:
produitsCategories: ['Alimentation', '...']
With that field in place you can then query it with:
collectionRef.where('produitsCategories', arrayContains('Alimentation'))
One of my collections in Cloud Firestore has an where each item in the array contains three separate values (see the groupMembership field:
I know I can't write a query to find documents that match one of the array values. Is there a way to write a query to find documents that match a specific value for all three items?
For instance, I want to find all users where the groupMembership array contains one object that is equal to groupId: X, groupName: Y, membershipStatus: active
You can pass the entire object in an array-contains clause.
So something like:
usersRef
.whereField("groupMembership", arrayContains: [
"groupId": "kmDT8OUOTCxSMIBf9yZC",
"groupName": "Jon and Charles Group",
"membershipStatus": "pending",
])
The array item must completely and exactly match the dictionary you pass in. If you want to filter only on some of the properties in each array element, you will have to create additional fields with just those properties. For example, it is quite common to have say a field groupIds with just the (unique) group Ids, so that you can also filter on those (of course within the limits of Firestore's queries).
I'm facing with mongodb for querying the array of array fields
I am able to access the 'feild1.feild2' but its returns the value
field1:{field2:[Array]}
field1:Object
field2:[Array]
0:Array
0:Object
My Real Dataset are:
customerData:Object
sendtocustomerlist:[Array]
0:Array
0:Object
Name:xxx
phone:xxxxxxx
I want to access the field2 and the nested arrays to get the Object values. Help with that.
you can use arrayElemAt:
here is the link:
https://docs.mongodb.com/manual/reference/operator/aggregation/arrayElemAt/#exp._S_arrayElemAt
I have an Algolia Index that contains objects like this:
id: 2,
name: test,
important: ["lorem", "ipsum", "dolor", "sit", "amet"]
I want to retrieve all entries that e.g. contain either "dolor" or "sit".
How would I go about this?
Note: This is just an example, the importantarray of each entry would normally contain around 1 to 4 values (in total around 1.000 possible values). The array to filter it by / to search for could have anywhere between 1 to 400 values.
What AFAIK doesn't work:
searching in Facet Values by using a facetQuery: facetQuery does not allow for boolean operators. Therefore I can only search for only one of "dolor" or "sit" at once, see docs.
The filters docs however says
Non-numeric attributes (e.g. strings) need to be set up as categories, which we call facets.
So I am wondering if this is possible at all...? Or maybe I am approaching this issue the wrong way?
You are looking at the right place and need to combine attributesForFaceting and filters:
set the important attribute as an attributesForFaceting either via API or the Dashboard
then use the filters to filter on your desired values
Your filter will look like this: { "filters": "important:dolor OR important:sit" }