Facebook API, Querying the "stream" table returns "null" for the "type" field - facebook-fql

Running this FQL query in the API explorer :
SELECT post_id,actor_id,target_id,type,permalink,type,message FROM stream WHERE source_id=104266592953439 AND is_hidden=0 LIMIT 0,50
returns null for every "type" field. Why is correct "type" field not showing up ?

I tried that query and also got type as null, but when i changed the WHERE to "WHERE source_id=me()" , I say the correct type for each post.
I'm not entirely sure, but it might have something to do with the source_id you are specifying. Maybe since it is a page and not an actual user, the type won't be returned.
Once again I'm not positive, but it might be something you can look deeper into.

Related

Find documents with a certain field value only when another field value is a given string

I'm using this php package to make queries - https://github.com/jenssegers/laravel-mongodb
The situation is, there are two fields, user_id and post_status among others. I want to retrieve all the documents in that collection, but when post_status field value is draft, that should be retrieved only when user_id is a given string. The idea is, only logged in user finds their drafted posts among other posts.
I'm having hard time finding any solution for this problem. The app is still not in production. If I should store data is some different manner, that is an option as well.
Find documents with a certain field value only when another field value is a given string
The question your are framing is simply convert into a and query, how let's see it
when another field value is a given string
This means that you have some result sets and you need to filter out when user_id match with some string. i.e some result sets and user_id = <id>
Now consider the first part of the sentence Find documents with a certain field value
This means you are filtering the records with some values i.e "status" = "draft" and whatever result will come and want again to filter on the basis of user_id = <id>
So finally you will end-up with below query:
db.collectionName.find({"status":"draft", "user_id": "5c618615903aaa496d129d90"})
Hope this explanation will help you out or you can rephrase your question I will try to modify by ans.

Is it possible to search within a MongoDB field with type of Date or Int?

I have a search field within my application that I want users to enter a search term into and it searches across various fields in each Mongo document. Naturally, I can search data within the fields that are of type String (currently using a regular expression), but how do I do this for those with type Date or type Int that?
Note: when I say search within the field, I mean if a user types '16' into the search field, it will return dates that contain '16', e.g. 01/01/2016 or 16/03/2014. Same principle for integers.
One quick way I think is you can use $where
value to search val = "16"
db.foo.find({$where : "function(){ if(this.dateField.toString().indexOf(val)>= 0 || (""+this.intField).indexOf(val)>=0){return true;}}"})
What basically you can try is convert the field value into string and then search it in there. Downside is $where doesn't uses index, it basically scans the collection, You cannot use other operators when you are using $where.
Yes it is possible.
You can tell your find() to look into only fields which are of specific data types.
$type comes handy.
check out the following link for examples and usage.
https://docs.mongodb.com/manual/reference/operator/query/type/
an example would be
db.addressBook.find({"field": "search-value"}, { "field" : { $type : "double" } } )
will return documents where search-value has a match as well as if the field is of type double.
since i have an image hence posting it as another answer rather than a comment.
now if you notice, documents with ID 2 and ID 6 are exactly the same. Only difference is the data type for the zipcode field.
i ran my query with $and as you can see and it bring backs only the matching record. if i get rid of the $and and the $type condition it will bring back both the records.
i hope this will help you solve your issue.

How to structure a limited query in AirTable

This is bringing back too much data,
https://api.airtable.com/v0/MyAccoutNumber/Movies?&api_key=MyKey
How can I just have it bring back the film names for instance. I have tried putting in various changes into the query but either an error occurs or the very same amount of data returns?
You can use the fields parameter to limit which fields are returned in the results. fields takes an URL-encoded array of field names or IDs.
For example, if you only want two fields called "Name" and "Year" returned in the results, the request would look like this:
/v0/appId/tableName?fields%5B%5D=Name&fields%5B%5D=Year
You can see jQuery.param as a reference for URL-encoding arrays and objects. In this case, jQuery.param({fields: ["Name", "Year"]) returns fields%5B%5D=Name&fields%5B%5D=Year.

How can i change _id field in MongoDB Collection to User_id?

I am new user for MongoDB Database. In MongoDb whatever insert into some collection defaultly one field is added that is _id field.
For Example:
db.users.insert({"User_id":"1","User_Name":"xxx","Address":"yyyy"})
db.users.find()
It shows
{ "_id" : ObjectId("528475fc326b403f580d2eba"), "User_id" : "1", "User_Name" : "xxx",Address" : "yyyy" }
I don't need _id field and i want to replace that _id field to User_id with auto increment values.
Is it possible. Please help me. Thanks in advance.
_id field is really special in mongodb. This is your primary key there and there is no way you can have a document without it. Even if you are trying to insert the document without it, mongo will create it for you (as in your example). Moreover, you can not even modify _id field for you collection.
But you can create a document with your own _id. So if you want you can do db.users.insert({"_id":"1","User_Name":"xxx","Address":"yyyy"}) \\why exactly 1 is a string?
and remember that _id means user_id and also keep in mind that this _id should be unique
Keep in mind that mongodb is not like sql. It does not have autoincrement keys (by this I mean that it is not that creators did not know how to do it, but just that you can leave pretty much without it), but you can achieve create something that would resemble the same behaviour.
As for as I can understand your problem is that you want to use your mongoDB internal _id as your custom attribute. For example suppose the db contain the user Identity and having attributes like "_id , name , address ..." and you want to use this _id's value in your application as userId for external reference.
So as #SalvadorDali said _id field is really important in the mongoDB and you can not have a document without it. All you can do is let the db store the value by it's default _id but you can access outside using your own User_id by applying these two changes in your json file.
"properties": {
"userId":{
"type": "string",
"id":"true",
"index":"true",
"description": "unique id of identity"
}
}
now you store any unique value, it is stored in the db using default _id and outside you can have that value in userId field.
Correct me if i got your question wrong.

Query every liked object using FQL

I'm trying to query every object which the user has liked since joining facebook by running this query:
SELECT user_id, object_id, post_id FROM like WHERE user_id=me()
This query runs fine and returns some results, but the number of them is a lot less than I estimated. I tried it on different, real user accounts, and for a friend of mine who has joined facebook around 2006 the number of returned results is still only around 65.
I tried this query through the official javascript sdk and through the graph api explorer which gave identical results.
The documentation doesn't state any limit imposed upon querying the like table.
Is there anything, I should be aware when doing a query on this table?
Thank you very much!
According to this documentation :
Each query of the stream table is limited to the previous 30 days or
50 posts, whichever is greater, however you can use time-specific
fields such as created_time along with FQL operators (such as < or >)
to retrieve a much greater range of posts.
Although not explicitly mentioned in the doucmentation for likes, I guess this will be the same limit. So try to add created_time in a where clause.