MongoDB Get Multiple objects with the same name within objects with different name: - mongodb

So I can't seem to get the results I want so I'm asking for your kind help on it. Imagine a MongoDB database built for multi-language content, something like this:
"info": {
"en": {
"greetings": {
"hello":"hello",
"goodbye":"goodbye"
},
"directions": {
"left": "left",
"right": "right"
}
},
"pt": {
"greetings": {
"hello":"olá",
"goodbye":"adeus"
},
"directions": {
"left": "esquerda",
"right": "direita"
}
}
}
Now if I want to query in order to get the directions object in both English and Portuguese but not the greetings, how should I do it?
If it helps, my purpose is to subscribe to exactly that content on a meteor app's template, so no need for all other objects within a given language object, just the one I need for any given template.
Thanks in advance!

how about you iterate?
db.collection.find().forEach((language){
some code here
})

Related

Retrieve ALL Github issues of a specific Project using the GraphQL API

I've been trying to retrieve all GitHub issues of a specific project using their GraphQL API.
The problem that i have is that i need to specify in the items a first or last param it doesn't work. Although by specifying one of these params i get only a partition of the issues.
I thought that i could get the first 100, then use pagination and get the other 100 etc until the response is an empty list. From what i read, i cannot find a parameter in the items that defines a page.
What are your thoughts on this? Is there a workaround?
Thanks a lot for your time.
This query seems to work fine and gives page info under items,
query{
organization(login: "microsoft") {
projectV2(number: 559) {
title
items(first: 100) {
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
Output,
{
"data": {
"organization": {
"projectV2": {
"title": "Azure TRE - Engineering",
"items": {
"pageInfo": {
"endCursor": "Njc",
"hasNextPage": false
}
}
}
}
}
}
Tested the query using,
GitHub Explorer

How to generate automatic Id with Commit or Batch Document Firestore REST

Hi I am creating documents with commit like this way:
{
"writes": [
{
"update": {
"name": "projects/projectID/databases/(default)/documents/test/?documentId=",
"fields": {
"comment": {
"stringValue": "Hello World!"
}
}
}
},
{
"update": {
"name": "projects/projectID/databases/(default)/documents/test/?documentId=",
"fields": {
"comment": {
"stringValue": "Happy Birthday!"
}
}
}
}
]
}
The parameter ?documentId= dosen´t work like when creating a single document, if I left empty I get an error that I must specify the name of the document so how I can generate an automatic id for each document?
Unfortunately, batch commits with auto generated documentId are not possible in the Firestore REST API. As you can see in this documentation, the Document object should be provided with a full path, including the documentID:
“Name:string
The resource name of the document, for example projects/{project_id}/databases/{databaseId}/documents/{document_path}.”
And if it was possible to omit the documentID, it would be mentioned in this documentation.
If you would like to have this implemented in the Firestore REST API, you can create a feature request in Google’s Issue Tracker so that they can consider implementing it.
I just came across the same problem and discovered that it is still not implemented.
I created a feature request for it here: https://issuetracker.google.com/issues/227875470.
So please go star it if you want this to be added.

How to query all languages from GitHubs graphql

I am trying to query GitHub for information about repositories using their v4 graphql. One of the things I want to query is the breakdown of all the languages used in the repo. Or if possible, the breakdown of the languages across all of a user's repos. I have tried the following snippet, but it returns null, where as primary language returns the primary language
languages: {
edges: {
node: {
name
}
}
}
The only thing I can find relating to languages is the primary language. But I would like to show stats for a user and the all languages they use either in a single repo or across off their repos.
You are missing the slicing field, here you can put first: 100 to get the first 100 languages for the repository:
{
user(login: "torvalds") {
repositories(first: 100) {
nodes {
primaryLanguage {
name
}
languages(first: 100) {
nodes {
name
}
}
}
}
}
}
If you want to have stats per language (eg if you want to know which is the second, third language etc...) I'm affraid this is not currently possible with the graphql API but using the List Languages API Rest for instance https://api.github.com/repos/torvalds/linux/languages
I wanted to point our something else that may help.
You can get more details about a language (i.e. primary, secondary etc) by looking at the language size. Comparing the totalSize for the whole repo to the size for each language it has.
The following query (example for pytorch) will get the data you need. Put it into the GH's GQL Explorer to check it out.
{
repository(name: "pytorch", owner: "pytorch") {
languages(first: 100) {
totalSize
edges {
size
node {
name
id
}
}
}
}
}
You will get an output of the form
{
"data": {
"repository": {
"languages": {
"totalSize": 78666590,
"edges": [
{
"size": 826272,
"node": {
"name": "CMake",
"id": "MDg6TGFuZ3VhZ2U0NDA="
}
},
{
"size": 29256797,
"node": {
"name": "Python",
"id": "MDg6TGFuZ3VhZ2UxNDU="
}
}, ...
To get % for each language just do size / totalSize * 100

Custom filters that accept objects - lighthouse-php

I am using lighthouse-php as Api Gateway in a micro services architecture.
So for all my types I make a request internally through Guzzle.
But I am needing to implement filters that are suitable for any type and that give flexibility when making queries.
I need to implement a query like this:
query news (
order_by: {publication_date: desc}
where: {
_or: {categories_id: { _eq: 1 }, title: { _ilike: "news" } }
}
limit: 10
offset: 20
) {
id
category_name: name
photo
publication_date
text
title
}
But I have no idea how to implement this "where" filter that receives a composite object as in this example.
Remember that this query will not use any model within lumen, since it will be a custom query that will make a request to the microservice of news.
What I need is the way that my query receives whatever comes in where, limit and order, to send it on request. But I have no idea how to build something like this in the scheme.
Anyone have any idea how to do it?
Thanks friends.
Yes, you can.
Just now I'm making an component that will receive criterias to filter in graphql query so I need to fill filter's where params with those criterias.
Imagine the following schema:
type News{
id: ID!
title: String!
views: Int!
}
type Query{
getNews(where: _ #whereConditions(columns:["title", "views"])) : [News!] #all
}
We can make a query and fill where variables later
query GetNews($whereNews: [GetNewsWhereWhereConditions!]){
getNews(where: {OR: $whereNews}){
title
views
}
}
When querying we can fill the variables sending an object like
{
"where":[
{"column": "TITLE", "operator": "LIKE", "value": "Amazing title"},
{"column": "VIEWS", "operator": "GTE", "value": 10,
]
}

Display information of mongodb

Hi all I am very new in mongodb and I have some problems when I try to do some find in a collections I hope so someone can help me.
Imagine I have the following collection:
db.fechasCambio.insert(
{
columns:[
'Divisa',
'05/10/2015',
'02/10/2015',
'01/10/2015',
'30/09/2015',
'29/09/2015',
'28/09/2015',
'25/09/2015',
'24/09/2015',
],
data:[
{
'Divisa':'USD',
'05/10/2015':'11236',
'02/10/2015':'1116',
'01/10/2015':'11153',
'30/09/2015':'11203',
'29/09/2015':'11204',
'28/09/2015':'1117',
'25/09/2015':'11151',
'24/09/2015':'11241'
},
{
'Divisa':'BGD',
'05/10/2015':'19558',
'02/10/2015':'19558',
'01/10/2015':'19558',
'30/09/2015':'19558',
'29/09/2015':'19558',
'28/09/2015':'19558',
'25/09/2015':'19558',
'24/09/2015':'19558'
},
{
'Divisa':'CYP',
'05/10/2015':'0',
'02/10/2015':'0',
'01/10/2015':'0',
'30/09/2015':'0',
'29/09/2015':'0',
'28/09/2015':'0',
'25/09/2015':'0',
'24/09/2015':'0'
}
]
}
) c
Now I want do some find inside the collections for example:
A-I want to bring me all currencies search by date range 05/10/2015 to 01/10/2015 then I need that return something like this:
{
columns:[
'Divisa',
'05/10/2015',
'02/10/2015',
'01/10/2015',
],
data:[
{
'Divisa':'USD',
'05/10/2015':'11236',
'02/10/2015':'1116',
'01/10/2015':'11153',
},
{
'Divisa':'BGD',
'05/10/2015':'19558',
'02/10/2015':'19558',
'01/10/2015':'19558',
},
{
'Divisa':'CYP',
'05/10/2015':'0',
'02/10/2015':'0',
'01/10/2015':'0',
}
]
}
I want to know what is the structure of the find that I need to use for have a result similar.
B-Also I need to know how do a find that return all the information related with a currency, for example I want searh all releated with the currency 'USD', I need return something similar to:
{
columns:[
'Divisa',
'05/10/2015',
'02/10/2015',
'01/10/2015',
'30/09/2015',
'29/09/2015',
'28/09/2015',
'25/09/2015',
'24/09/2015',
],
data:[
{
'Divisa':'USD',
'05/10/2015':'11236',
'02/10/2015':'1116',
'01/10/2015':'11153',
'30/09/2015':'11203',
'29/09/2015':'11204',
'28/09/2015':'1117',
'25/09/2015':'11151',
'24/09/2015':'11241'
}
]
}
I want to know what is the structure of the find that I need to use for have a result similar.
C-And finally I need to know how do a find that return all the information related with a value, for example I want search all the information with value of 0 between 12000, I need return something similar to:
{
columns:[
'Divisa',
'05/10/2015',
'02/10/2015',
'01/10/2015',
'30/09/2015',
'29/09/2015',
'28/09/2015',
'25/09/2015',
'24/09/2015',
],
data:[
{
'Divisa':'USD',
'05/10/2015':'11236',
'02/10/2015':'1116',
'01/10/2015':'11153',
'30/09/2015':'11203',
'29/09/2015':'11204',
'28/09/2015':'1117',
'25/09/2015':'11151',
'24/09/2015':'11241'
},
{
'Divisa':'CYP',
'05/10/2015':'0',
'02/10/2015':'0',
'01/10/2015':'0',
'30/09/2015':'0',
'29/09/2015':'0',
'28/09/2015':'0',
'25/09/2015':'0',
'24/09/2015':'0'
}
]
}
I want to know what is the structure of the find that I need to use for have a result similar.