Get node of data from firebase - javascript

i'm trying to get data from firebase and i'm little stuck with that.
i'm trying to get the all SemaA data
i did it like that but it not give me nothing
firebase.database().ref('Courses/'+departmentId+'/SemA'),
i can specific to do (but i don't want it)
firebase.database().ref('Courses/'+departmentId+'/SemA/java'),
i also wnated to get the black sign and red sign in two different queries and run into loop to get the data from there

If you're looking to loop over the courses in a semester:
var semesterRef = firebase.database().ref('Courses/'+departmentId+'/SemA')
semesterRef.on('child_added', function(courseSnapshot) {
console.log(courseSnapshot.key);
});

Related

How to get data after 10 data skip in Realtime database firebase javascript node js

I am using Node js with Express.js and I am getting data from firebase's real-time database
so How can I get data after 10 children or nodes by skipping?
example
I have a lot of data like -
Images
imageId
- {some properties ie: imgUrl:"somevalue.jpg"}
and more
So first I am taking first 10 images using limitFirst(10) function.
and if the user clicks on link or next button I want to load the next first 10 images if available
does firebase real-time database have some functionality like this
//limitToAfter(afterChild, limit);
const imageRef = query("Images", limitToAfter(10,10));
onValue(imageRef,(snapshot)=>{
//some operation here...
});
Or can anyone give me some ways I can solve this problem?
I will always appreciate any help :)
Firebase Realtime Database doesn't have an offset mechanism. Instead to get the next page of data, you need to know the last node on the current page.
For example, say that the key of the last item on page 1 is "key10", then you can get the next 10 items with:
query("Images", orderByKey(), startAfter("key10"), limitToFirst(10));
In words: take all nodes under Images, order them by their key, then start after "key10" and return the first 10 nodes.

React Native Aws Amplify DataStore What Is the Logic Behind?

I have many to many relational data model. For example , i have a chat room and it has many users.
{Chatroom:
ChatRoomID:ID,
Somedata...
User:{
ID:userid,
Somedata...
}
}
I have a user object and i need to filtre those by user.
DataStore.query(ChatRoom,e=>e.User.Id("eq",myID))
I tried to query the data which has my userid then get the ChatRoomID. But i didnt work as expected. I can filter it with its main keys but i cant go through inside the object to filter. Currently i am doing this the same as the aws document. Which is-->
DataStore.query(ChatRoom).filter(e=> e.user.id==myID)
My concern is ,is this query above gets the whole data to filter ? For the first one, it looks like it getting the filtered data like select queries as we do in SQL. But i m worried about using second one. What if i have 100.000 rooms and 500.000 users inside it ? Is it get the whole data before filtering with a JavaScript functions like filter, map etc. ? I dont get the logic behind.

get foreignId Data from the feed of a user [Stream Js]

hi i'm trying to implement getstream.io in my project.
i'm using https://github.com/GetStream/stream-js
as my server side script is in nodeJS.
i'm able to create a user in feed using
user1 = client.feed('user', 'dpz');
i'm creating activity for this user using using
activity ={
"actor":"user:1",
"message": "#flat_4_bfcaffca-c35f-11e5-8080-8001002e75f6",
"verb":"tweet",
"object":"tweet:4",
"foreign_id": "flat:4"
};
user1.addActivity(activity);
if i want to get all records of that user,
i use
user1.get()
.then(function(body) { console.log(JSON.stringify(body)); })
.catch(function(reason) { console.log(JSON.stringify(reason.error));});
i get result as :
{"duration":"19ms",
"next":"",
"results":[{
"actor":"user:1",
"foreign_id":"flat:4",
"id":"41231d40-ca5a-11e5-8080-800047dac62a",
"message":"#flat_4_bfcaffca-c35f-11e5-8080-8001002e75f6",
"object":"tweet:4",
"origin":null,
"target":null,
"time":"2016-02-03T09:41:09.335584",
"to":[],
"verb":"tweet"
}]
}
in your rest_ documentation
https://getstream.io/docs_rest/#feed_detail
you have specified
feed/(feed_slug)/(user_id)/(activity_id|foreign_id)/
to delete an activity for if the foreign key matches criteria.
in your nodejs code
user1.removeActivity({foreignId: 'flat:4'})
line works to remove the feed for that user where foreign key is flat:4
user1.get({foreignId: 'flat:4'})
does not work
can you please help if i want to get feeds with the foreignId as 'flat:4'
is there any way for such ?
please help as i'm stuck on this point only.
The feed/(feed_slug)/(user_id)/(activity_id|foreign_id)/ endpoint is only for DELETE requests. At this present is not possible to retrieve activities by its foreign_id. That field can only be used to perform cascaded deletion and/or to define the uniqueness of your data.
Looking at the code that you added, it seems like to use references to feeds as the value for foreign_ids, if that's the case then you are probably using this field in a weird/wrong way and you should create a new question on SO to ask help with the integration of your data.

Trello API: how to get board ids of an organisation or member

I am working on a Trello sync bot based off of the GitHub one here : https://github.com/fiatjaf/trello-cardsync and I am working on the coffeescript files. I have looked on the API and I think I know what I need I just don't know how to write it exactly and I can't find any examples of it especially in coffeescript (or javascript).
I would like to be able to search through an organisations boards or a members boards and then pick out certain board IDs so I get just a list of board IDs to certain boards I want, so then I can create webhooks for these boards.
I've tried using Trello.get("members/me/boards", { fields: "id, name"}) to get all the boards IDs and names like in the client.js API 'Trello.get(path[, params], success, error)' but my GET just returns unidentified when I try to print it to console. I have an array of objects in the settings.coffee file to compare the names with to select the boards I want but I can't get the full list in my file. At the moment I'm just looking at the data from the link: https://trello.com/1/members/my/boards?key=substitutewithyourapplicationkey&token=substitutethispartwiththeauthorizationtokenthatyougotfromtheuserand entering the IDs manually to create the webhooks, but I would like to automate this as much as possible.
I have also looked at 'GET /1/search' in Trello API but I'm unsure how to do that in my coffeescript file.
You need to pass a callback to Trello.get. It doesn't return anything meaningful, but instead passes the value to the callback:
Trello.get("members/me/boards", { fields: "id,name"}, function(err, boards) {
console.log(boards); // got them!
console.log(err); // if something went wrong, this will be non-null
})

Single query or multiple queries on mongodb with mongoskin???

this is on mongodb
{cod_com:'WWWOAN',
cod_prod[{prod:'proda',info:'hola mundo'},{prod:'pacda',info:'hola mundo'},{prod:'prcdb',info:'hola mundo'}]
}
{cod_com:'WWWOA2',
cod_prod[{prod:'prdda',info:'hola mundo'},{ccod:'prcda',info:'hola mundo'}]
}
{cod_com:'WWWOA1',
cod_prod[{prod:'prcda',info:'hola mundo'},{aaad:'prcda',info:'hola mundo'}]
}
i have to get the info inside the cod_prod variables... so im working with two steps
first i query the owner of the cod_prod
db.collection.findOne({cod_com:'WWWOA1'});
if exists, i query the cod_prod that i need
db.collection.findOne({'cod_prod.prod':'prcda'});
so basically im querying two times, first is to the the owner of the product, and the second the info of the product that im searching...
the question is, there is any way to search the prod directly???
i cant use this...
db.collection.findOne({'cod_prod.prod':'prcda'});
because differents owners has same product... so first i get the owner and second i get the product....
anybody has a better aproach?? or a different way to get the info??? tnx
If you query like this:
db.collection.findOne({'cod_com':'WWOA1', 'cod_prod.prod':'prcda'});
you should get the result you want.

Categories

Resources