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.
Related
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.
I'm having trouble trying to figure out how to get a list to query as desired. Full disclosure, it may not be possible and if that's the case then at least it will provide me with some closure. I want to query a friend's list based on presence, where friends who are active are queried on top.
Here is my database structure:
friendships
$UID
$UID: true
users
$UID
active:true/false
I need the list to stay synced so I need to use .on('value'). I've tried a couple different methods using child_added as well as iterating through a snapshot using snapshot.forEach() and pushing the childSnapshot key:value pairs into an array so I could then use lodash to order the list via the active key on the client side, but ran into the issue of it pushing a "new" item into the array for each active value change so there would be multiple items for any given user.
Any help or insight would be appreciated, spent the majority of yesterday attempting to figure this out before resorting back to an unorganized list using the following code:
const {currentUser} = firebase.auth();
firebase.database().ref(`/friendships/${currentUser.uid}`).on('value, snapshot => { //redux dispatch action, payload: snapshot.val() })
There's no great solution for this. Firebase doesn't have any sort of join or join query, so you could do usersRef.orderByChild('active').equalTo(true), but that will just return you all active users. You'll need to do separate queries to pull in their friendships.
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);
});
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.
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
})