#Database Operation Keyword "Query.contains()"

58 messages · Page 1 of 1 (latest)

humble rapids
#

My app is a social App where user can follow and unfollow each other,
right now I don't know what i'm doing wrong but i want to be able to get posts of users if the user its contain in the array of user i'm following

Here is my Code

        databaseId: Common.dataBasesId,
        collectionId: Common.collectionStoryTellerId,
        queries: [
          Query.orderDesc('\$createdAt'),
          Query.limit(500),
          // Query.equal("userId", userId),
          Query.contains("userId", ['${userModel.following}']),
        ],
      );

  return doc.documents;

Please, what i'm missing out on?

tidal spade
plucky crescent
#

Ooooh okay,

So @tidal spade what if the attribute it's not an array but the value to check with it's an array.

Let me give examples,
I have a collection called storyTeller and It has userId (string attributes) of people who created document in the collections.

And I have follower ( string array) and I want to check if any of my follower has made a post in the storyTeller collection

How do I do that?

tidal spade
plucky crescent
#

Honestly @tidal spade I have read it, one of my tab is open on it,

I'm confused on how to go about this

tidal spade
humble rapids
#

okay, thanks @tidal spade for putting more light into this

i did that i and i'm getting everything in the collection instead of just one document to be returned

This is my follower [2349034286339, 2348148422710]

only 2348148422710 have created a docement in the storyTeller Collection but instead i'm getting result of another,

what do i do here?

tidal spade
humble rapids
#

Here is the code

        databaseId: Common.dataBasesId,
        collectionId: Common.collectionStoryTellerId,
        queries: [
          // Query.equal("userId", userId),

          Query.orderDesc('\$createdAt'),
          Query.limit(500),
          Query.or([
            Query.equal("userId", ['${userModel.following}']),
            Query.isNotNull("userId")
          ]),
        ],
      );

 return doc.documents;

userModel.following contains [2349034286339, 2348148422710]

humble rapids
#

okay,

Appwrite exception scream out me that at least two query its needed, and i dont know which query to use there

tidal spade
humble rapids
#

@tidal spade please how do i proceed to get the desire result i want?

tidal spade
humble rapids
#

have multiple times

tidal spade
humble rapids
#

yes

tidal spade
humble rapids
#

now i'm getting
AppwriteException: general_query_invalid, Invalid query: Query value is invalid for attribute "userId" (400)
whereas i have userId in the indexes

#

here is the code now

        databaseId: Common.dataBasesId,
        collectionId: Common.collectionStoryTellerId,
        queries: [
          // Query.equal("userId", userId),

          // Query.orderDesc('\$createdAt'),
          Query.limit(500),
          Query.or([
            Query.equal("userId", [userModel.following]),
          ]),
        ],
      );
    }

    return doc.documents;```
#
  1. when i do it like this
        databaseId: Common.dataBasesId,
        collectionId: Common.collectionStoryTellerId,
        queries: [
          Query.orderDesc('\$createdAt'),
          Query.limit(500),
          Query.or([
            Query.equal("userId", ['${userModel.following}']), //attention here
          ]),
        ],
      );```


i get this error `AppwriteException: general_query_invalid, Invalid query: Or queries require at least two queries (400)`

what i'm i missing out here @tidal spade
tidal spade
humble rapids
#

ofcourse i did @tidal spade

tidal spade
humble rapids
#

@tidal spade Query.equal() was the first Query i used, it not worked for me

tidal spade
humble rapids
#

okay following the code sample at the bottom of the above url
i edited my code to this

        databaseId: Common.dataBasesId,
        collectionId: Common.collectionStoryTellerId,
        queries: [
          Query.orderDesc('\$createdAt'),
          Query.limit(500),
          Query.equal("userId", userModel.following),
        ],
      );```

and i keep getting this error `AppwriteException: general_query_invalid, Invalid query: Query on attribute has greater than 100 values: userId (400)`
humble rapids
#

i think i do,
the number items inside the userModel.following is more than 100 values

humble rapids
#

i really dont know what to do

tidal spade
tidal spade
humble rapids
humble rapids
#

i dont know what the second queries should be

tidal spade
tidal spade
humble rapids
#

@tidal spade i cleary dont know what should be done beyound this point

tidal spade
#

Start with this:

          Query.or([
            Query.equal("userId", 100Followers),
          ]),
        ],

And you have another100Followers. What would you do?

humble rapids
#

i dont get to know if a follower on the follower list its 100 or above 100

humble rapids
tidal spade
#

Why can't you tell if a list has more than 100 items?

plucky crescent
#

Using the length to determine the size of item in the array does not change the fact that the Query.equal() needs only 100 items in the array,

The more pressing issues right now @tidal spade is how do we get post of users irrespective if the array has fewer items less than 100 or above 100

#

You said I should study the doc via the link you supplied, I have done that sand still not getting the expected results

#

<@&634618551491100692> , I'm having issues trying to understand the use of Query.or() and Query.and()

I'm actually coming from a PHP SQL, maybe because of background I can't fully grasp the power of Query.or() and Query.and() in Appwrite concept (I thought it's the same everywhere)

Please I will be very grateful if anyone can actually point me the right thing to do

sullen mist
#

Do you really need to apply the query with 100 and get 500 elements?

plucky crescent
#

This is what I aim to achieve,
I have list of posts in my storyTeller Collection and it has a userID attributes of String and I want to check the userId with a string arrays of list of followers

So basically, if any users in follower array list make a post, retrieve all those documents that matches the users

tidal spade
tidal spade
tidal spade
tidal spade
grim burrow
plucky crescent
#

Okay noted